Memory increase during picturebox animation
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)
For i As Int32 = 0 To V.CellCount - 1
'Draw a bunch of blobs and crosses
Me.picBanner.Image = nBitmap
AnimationInProgress = False
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?
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.
"There are two ways to write error-free programs. Only the third one works."
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
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.
By Filbert in forum Talk to the Editors
Last Post: 09-20-2005, 07:03 PM
By Eric Immerman in forum .NET
Last Post: 04-29-2002, 12:55 AM
By Geoff Lingham in forum VB Classic
Last Post: 04-22-2002, 06:46 PM
Last Post: 11-02-2001, 05:22 PM
By John Harkin in forum Database
Last Post: 09-13-2001, 05:57 AM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL