473,396 Members | 2,037 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,396 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 1321
"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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.