Search code examples
c#.netbitmapdispose

Does System.Drawing.Bitmap disposes data in it's destructor?


I'm using .net Bitmap in many projects without disposing it's data explicitly with Dispose() and leave the data disposal to Bitmap's destructor.

Is my thinking true and Bitmap's destructor disposes the data?


Solution

  • Yes, it will release the native GDI+ image. But it's still better to dispose it manually if you can, because there is no telling when the GC will collect and finalize the object. And if you somehow kept a reference to the Bitmap, the GC won't collect it at all, so the native image won't be released...