"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