Click to See Complete Forum and Search --> : Memory issue


vandel212
November 24th, 2009, 01:26 PM
I'm writting an application that takes a screenshot and allows the user to draw on it. The problem is that when I look at the memory usage, every time I draw a line or something it uses up 10 more MB and eventually uses up 1.5GB of memory and then for a reason I'm not sure of, it drops down to about 250MB and keeps doing that. My guess is that it has something to do with the Bitmaps I'm making. I have a bitmap that updates eveytime a line is drawn and 3 more bitmaps to contain the three previous images so that the user can undo their work. This works without a problem except that it uses up a lot of memory. Is there any way I could release the memory being used so that it doesn't keep building up to 1.5GB of memory usage?

Thanks in advance.

Mutant_Fruit
November 24th, 2009, 01:55 PM
When you're finished with your resources, call Dispose on them.

boudino
November 25th, 2009, 01:34 AM
Maybe your are creating a copy of the bitmap every time you draw on it? If so, avoid it and draw directly in existing bitmat. Also make sure that you dispose resources properly as Mutant Fruit has suggested. What happens to the 4th extra bitmap if you create a new one? Do you dispose it properly? If its reference is not stored on unwinded stact, it wouldn't be disposed automatically by GC.

vandel212
November 25th, 2009, 01:14 PM
After the 4th bitmap I have it cycle back to the first bitmap I use for undoing. It overwrites that bitmap and continues the cycle. I think I figured out what I needed to do I call the garbage collector after it writes the 4th bitmap. It keeps the Memory usage down to constant 50MB, which is what I expected from the beginning.

Thanks for the help.

Mutant_Fruit
November 25th, 2009, 02:16 PM
Nope, you definitely should not be calling the garbage collector.


After the 4th bitmap I have it cycle back to the first bitmap I use for undoing. It overwrites that bitmap and continues the cycle.

Without seeing any code samples, my bet is this is where the bug is and the bug is a missing call to Dispose.

Want to paste the relevant code snippets so the real bug can be found?