CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Memory issue

  1. #1
    Join Date
    Feb 2009
    Posts
    112

    Memory issue

    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.
    - It's a long way to the top if you want to rock n' roll - AC/DC

    Check out my band and support the music:
    www.blueruinmusic.com

  2. #2
    Join Date
    May 2007
    Posts
    1,546

    Re: Memory issue

    When you're finished with your resources, call Dispose on them.
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

  3. #3
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Memory issue

    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.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  4. #4
    Join Date
    Feb 2009
    Posts
    112

    Re: Memory issue

    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.
    - It's a long way to the top if you want to rock n' roll - AC/DC

    Check out my band and support the music:
    www.blueruinmusic.com

  5. #5
    Join Date
    May 2007
    Posts
    1,546

    Re: Memory issue

    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?
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured