Re: Display a bitmap from Win32, unmanaged code?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Tue, 05 May 2009 08:45:00 -0700, bsnguy <bsnguy@xxxxxxxxxxxxxxxx> wrote:

[...]
So I said "hey, dispose of the bitmap" and I added

theBitmap.Dispose();
This works, for a while. The problem is that depending on what I do in the
UI, it seems that the bitmap is being disposed before the picturebox has
actually displayed it and I get an exception. Is there a better way to handle this?

Yes. Don't dispose the bitmap until you're done with it. That is, wait until just before you've got a new one before you dispose the old one.

Pete
.



Relevant Pages

  • Re: memory leak
    ... Adding GC.Collectcauses the memory to drop, ... Now do you still agree that the GC will cleanup Bitmap objects? ... Dispose is not a required call - it is optional. ... done with those resources. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: memory leak
    ... Adding GC.Collectcauses the memory to drop, ... GC.Collect in the exception handler, ... Now do you still agree that the GC will cleanup Bitmap objects? ... Dispose is not a required call - it is optional. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: memory leak
    ... ArgumentException on Full Framework) when I have a ton of virtual memory ... "new Bitmap" line. ... Dispose is not a required call - it is optional. ... you are done with those resources. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: memory leak
    ... Adding GC.Collectcauses the memory to drop, ... Now do you still agree that the GC will cleanup Bitmap objects? ... Dispose is not a required call - it is optional. ... done with those resources. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Dispose
    ... It will look like that eventually, but for now it uses native implementation ... OS services which makes "managed" bitmap unusable. ... why should I have to Dispose of a Bitmap? ... understand the internals (pixels are create in C world), ...
    (microsoft.public.dotnet.framework.compactframework)