Re: Deallocating memory of a Bitmap created with a pointer to image bits



Obviously, if you've passed the image to picture boxes and other controls you cannot delete it until you've tidied up those references. Otherwise you'll get a null reference exception.

The rule is that you manage whatever you create and leave everything elsa alone for the objects that are responsible for them.


--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


<anpasq@xxxxxxxxx> wrote in message news:1182154305.247992.89130@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Your so simple answers does not resolve the problem because the bitmap
is referenced by other
objects (PictureBox and others) so to manually call dispose I should
write code to keep
track of all the references around....

A clean solution should be to derive from the Bitmap class and
override the dispose method..
but as u know it is a sealed class..

so any other ideas ?


On 16 Giu, 14:08, "Bob Powell [MVP]" <b...@xxxxxxxxxxxxxxxxxxxxxxx>
wrote:
You should call Dispose yourself when you've finished using the bitmap.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consultinghttp://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Trickshttp://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQhttp://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

<anp...@xxxxxxxxx> wrote in message

news:1181927989.663758.214860@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

> As described in the article KB814675
>http://support.microsoft.com/?scid=kb%3Ben-us%3B814675&x=9&y=17

> "When a Bitmap object is created with a pointer to image bits, the new
> object may or may not use the memory at that address as backing for
> the image. Therefore, the application must make sure that the memory
> can be used during the life of the Bitmap object"

> That's ok but ..
> As I know there is no way to know when the Bitmap object will be
> disposed.
> so when should the supplied memory deallocated ?

> Any Idea ?



.



Relevant Pages

  • Re: Thread and subject changing
    ... attribution from a message in an old thread/subject. ... reference to the articles you're quoting. ... References header or attribution line. ...
    (news.software.readers)
  • Re: any hydro peeps here?
    ... abstract articles of papers you can't get, Amazon book reviews of books you ... the hydroponics ... references to references that suggest it MAY BE true. ... "The Davis authors hypothesize that plants being defended by man-made ...
    (rec.gardens.edible)
  • Re: Filters
    ... non-existant articles, ... have to create a filter for each one of them (after tracking down ... You extract the MIDs from the the References: ... My news client doesn't filter on the References header ...
    (news.software.readers)
  • Re: Cross-Access-platform databases re-compiles or refreshes references for a long time
    ... First I thought it was some recompiling - but a full compile in vba takes only 5-10 seconds. ... Maybe it is checking up the references all over the application and recompiles. ... Searching MSDN for articles gives no results - it is often hard to find articles which addresses cross-product problems. ...
    (microsoft.public.access.modulesdaovba)