Memory increase during picturebox animation


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Memory increase during picturebox animation

  1. #1
    Join Date
    Feb 2006
    Posts
    2

    Memory increase during picturebox animation

    Hello,

    in my app I have a picturebox with ever changing content. I use the following code to redraw it:

    Private Sub DrawDiagram()
    Dim nBitmap As New Bitmap(500, 200, Format24bppRgb)
    Dim iG As Graphics = Graphics.FromImage(nBitmap)

    iG.Clear(Color.White)
    For i As Int32 = 0 To V.CellCount - 1
    'Draw a bunch of blobs and crosses
    Next
    Me.picBanner.Image = nBitmap
    Windows.Forms.Application.DoEvents()
    AnimationInProgress = False
    End Sub



    It all works, but it looks like the bitmaps remain in memory. The increase is quite drastic... about 5MB per second and it just keeps going.

    I tried disposing the bitmaps, forcing garbage collection, reusing bitmap objects.. to no avail.

    How do I stop this memory explosion?

    Thanks,
    David

  2. #2
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    create a new bitmap just to paint it in a PictureBox is quite expensive...can you just keep a copy in memory? secondly, in your code you do not dispose the Graphics object.
    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

  3. #3
    Join Date
    Feb 2006
    Posts
    2
    I've tried a lot more in the meantime. Reusing bitmap objects and graphics objects, I've created my own control that only drawn the bitmap in case of OnPaint etc. etc. I've tried pretty much everything I know is possible by now.

    Thing is... I made this kind of thing before and it worked fine then. I rewrote, ported, copy-pasted code from older projects that worked and still the **** memory is running away with itself.

    If I can't find a solution before midnight today I'll just abandon this and continue my app without it

    Thanks,
    David

  4. #4
    Join Date
    Aug 2005
    Posts
    19
    Were you by any chance creating some of that bitmap data from a stream? I remember something about possibly leaking memory if you don't explicitly close them, or if you resize or some such. The brain can't quite remember, but you might want to check on that.

Similar Threads

  1. Memory Question
    By Filbert in forum Talk to the Editors
    Replies: 1
    Last Post: 09-20-2005, 07:03 PM
  2. PictureBox Memory Leak??
    By Eric Immerman in forum .NET
    Replies: 8
    Last Post: 04-29-2002, 12:55 AM
  3. How to reference Memory Mapped File data directly
    By Geoff Lingham in forum VB Classic
    Replies: 5
    Last Post: 04-22-2002, 06:46 PM
  4. help memory
    By kathy in forum Java
    Replies: 0
    Last Post: 11-02-2001, 05:22 PM
  5. Replies: 0
    Last Post: 09-13-2001, 05:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center