473,395 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dispose GDI+ objects

What kind of GDI+ objects is needed to be disposed?
If they are the fields of the class , does that class need to implement the
IDispose interface?
If they are used only within a method (e.g. OnPaint), do I need to dispose
them at the end of each OnPaint method?
I want a guideline and reason for that. Thanks.
Jul 21 '05 #1
1 1320
"Franz" <nu**@nothing.com> wrote in
news:OW*************@TK2MSFTNGP12.phx.gbl...
What kind of GDI+ objects is needed to be disposed?
All that support the IDisposable interface
If they are the fields of the class , does that class need to implement the IDispose interface?
Yes.
If they are used only within a method (e.g. OnPaint), do I need to dispose
them at the end of each OnPaint method?
If you keep them in a member to reuse them later (in another call to
OnPaint), no. Otherwise yes.
I want a guideline and reason for that. Thanks.


The guidline is quite simple: If it's got a Dispose-method, dispose it as
soon as you don't need it any more (usually when the variable goes out of
scope or you assign a new value to it)

The reason: Unmanaged handles aren't as nice as managed references are; If
you don't free them explicitly, noone does. Also, sometimes the order in
which they are released is important. So if a class directly or indirectly
contains an unmanaged handle, it usually has a Dispose method.

There are plenty of articles on this in the MSDN, if you want to know more
about it.

Niki
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: #Hai | last post by:
Hi, I know that in C#, destructor is a finalize method. This means that the destructor is only called when the Garbage collector does it job. But the the GC is always does it job when the memory...
3
by: Rich | last post by:
I notice that lots of the GDI+ objects implement IDisposable: SolidBrush, FontFamily, Font, etc. If I don't explicitly call Dispose() on these guys after I'm done with them, what is the...
14
by: qrli | last post by:
I used to think that all objects that implement IDisposable should be disposed. But I found 80% of the classes implement IDisposable. But when I looked into the samples, most objects are not...
13
by: | last post by:
I'm curious if anyone knows why the C# and VB.NET compilers don't automatically call Dispose() on objects that support IDisposable when they go out of scope. I asked a co-worker and his response...
4
by: aaj | last post by:
Hi can anyone point to a good link explaining (simply) when I should use the dispose method. Sort of things I'd like to know are how does it differ from finalize in VB.net (or is it nothing...
156
by: Dennis | last post by:
Ok, I'm trying to dispose of every object that I create that has a dispose method based on advice from this newsgroup. However, I'm not sure how to dispose of the following object that was created...
1
by: Franz | last post by:
What kind of GDI+ objects is needed to be disposed? If they are the fields of the class , does that class need to implement the IDispose interface? If they are used only within a method (e.g....
4
by: Larry Lard | last post by:
I still don't really 'get' this. Why can't an object just release its resources in its Finalize method? Why when I create (eg) a Graphics object does it become *my* responsibility to say when I've...
44
by: Smokey Grindle | last post by:
I have a list box on my form, but I need to databind it to a data table that is a private member of the form's class... so I basically have Public Class MyForm priate m_MyTable as new datatable...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.