ofToString()

Placing the ofToString function inside draw() or update() will cause memory leakage, but it’s probably not supposed to be there at all…

are you sure? maybe post some code. i’ve been using it quite a bit and haven’t noticed.

here is an example, put this line inside draw() of the fontsExample project:

ofSetColor(0,0,0);
franklinBook.drawString(ofToString(counter,0), 100,560);

this will cause memory leakage. maybe its just a problem on windows?
to find out if your program has memory leakage go to windows task manager and press the processes tab. if the mem usage for your program is increasing, there’s a memory leakage somwhere in your program.

don’t know how you can check for memory leakage on mac…

alfred

you’ve got the precision set to zero

http://www.openframeworks.cc/documentat-…-ofToString

so im not sure if that would cause a problem.

try
ofToString(counter,2)

or just
ofToString(counter)

just as a test to see if you still get a memory leak. i know how to test for memory leaks, but i must admit i’ve not used the precision within ofToString yet

I use ofToString() all the time and check apps for memory leaks using Instruments on osx and haven’t seen any leaks. Just tested the current app I’m working on (which uses loads of ofToString in draw()) and no leaks. Looking at the code of ofToString() I can’t really see where the leak is anyway, its a super simple function! Are you sure the leak isn’t in franklinBook.drawString() ?

There’s a memory leakage anyway, the precision thing is just how the number is formatted, if set to zero the output will be formatted to integer, if not set you get the original, in this case floating point. The leakage is 60k anyway. It doesn’t really matter because the output string can easily be formatted elsewhere.

al

can you post the code of the project which is leaking? we can take a look on all platforms.

sometimes, on windows, it takes while for the applications memory to fully register on the task manager. for example, when I load a bunch of fonts, images, etc, it might not immediately creep up, until the application has run a bit. you may notice the application memory creep up a bit. This is especially true when you use quicktime, which manages it’s own memory.

take care
zach

[quote author=“zach”]can you post the code of the project which is leaking? we can take a look on all platforms.

sometimes, on windows, it takes while for the applications memory to fully register on the task manager. for example, when I load a bunch of fonts, images, etc, it might not immediately creep up, until the application has run a bit. you may notice the application memory creep up a bit. This is especially true when you use quicktime, which manages it’s own memory.

take care
zach[/quote]

hey zach

i just checked this problem with my other computer, it’s the same thing there, but the memory leakage is smaller (4k). i won’t post any code because i have moved the ofToString() away from my projects draw() and update() functions, but i’m sure you’ll see it if you place the line

franklinBook.drawString(ofToString(counter,0), 100,560);

in the draw() function on the fonts example. I have experienced that memory creep a little bit up in the start of execution, but with ofToString() it will keep crawling. Isn’t this a problem om mac?

alfred

I just tried -

there’s no leak on a mac, and on a pc, using CB, no leak…

on the pc, you sometimes see the app’s memory go up by 4k, but that is just paging I think, not a memory leak. I saw it happen only a couple times running the modified font example, but the memory was completely constant. it happens on most apps.

if you have a memory leaking example, please post it and we can take a look.

take care!
zach

hello,

i just tried compiling a program with ofToString() using the release setting in MVS2005 and there’s no memory leakage. but when compiling using debug there’s a leakage. maybe the problem is in visual studio?

Al

Hello!

There is a memory leak with std:stringstream (which is used in ofToString() ) in VisualC++ , use std::ostringstream instead, and it should be ok!

I spend hours to find who spend that 4ko/sec in one of my projects!! it seems to be a problem with the express version of VC++2005…

edit: oups, my post is a little in late…

Great! I still have this problem in debugging mode (now it leaks about 180K each second), but there seems to be no leakage when I compile a release-version, so it don’t really bother me that much. Is this the case for you as well?

BTW, the application I’m working on is eating memory. When i run it, it uses about 200 000K of memory, and that’s a lot I think. I mean, it’s a big project with lots of .png-pictures loaded in, but 200 000K? I might be doing something wrong…

How many png files do you have loaded?
and what size are they?

The Funky Forest installation I just did was using about 500MB of Ram - but I had tons of Png sequences. About 1200 png files.

I just counted, it’s about 60 files, probably a litte less. Nothing compared to Funky Forest. The total size of the picture folder is only about 3,5Mb but in the program I might draw the png-files multiple times. In the drum step sequencer I create a matrix of 16*12 small pictures contained in their own classes with additional fuctions as well. Maybe it would be smarter to use pointers here? I have tried to avoid pinters unless where it was neccasary… The program has grown large, in total the program has now 114 files (C++ + .h). I’m not sure if it is the pictures that eats the memory.

It will make sense to use pointers if you want to share resources. I.e. if multiple sprites should have the same texture. In this case you should load the pngs in a separate class, and your sprites should have ofImage* (instead of ofImage) pointing to the preloaded ofImages. This way there is no duplication. If it will only ever be one sprite per image, then you can go ahead and make your life a bit simpler by not using any pointers, and just adding an ofImage per sprite. Hope that makes sense.

Hi !

I have the same memory problem when i use ofImages. But there is something strange…

When my program is launched, it seems to take about 30mo in memory (to believe the xp’s process manager), but if i i reduce the program in the windows bar, and i restore it after, it take now 3mo !

Please try to make this experience and tell us if it is the same for you.

(ps: I run OF on msc++ 2005 & 2009 on windows xp)