PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
What do I need to clean up in dispose?
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
What do I need to clean up in dispose?
![]() |
What do I need to clean up in dispose? |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
We have various user controls and forms that will be loaded and unloaded
during a program run. I want to be sure we are not going to leak memory. In the InitializeComponent method a lot of events are being added via += calls. Do I need to clean any of these up? We create basic fonts as member variables. Do I need to dispose of them? We create pens and brushes as member variables. Do I need to dispose of them? I assume that any += delegate not in the InitializeComponent is up to me to clean up. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
> We have various user controls and forms that will be loaded and unloaded
> during a program run. I want to be sure we are not going to leak memory. The garbage collector should handle memory management for you - the dispose pattern is about ensuring the release of handles to system resources such as windows or files. > In the InitializeComponent method a lot of events are being added via += > calls. Do I need to clean any of these up? No. Event handlers will be cleaned up by GC. > We create basic fonts as member variables. Do I need to dispose of them? > We create pens and brushes as member variables. Do I need to dispose of > them? It used to be that GDI resources were scarce and you needed to clean them up as soon as you could after using them, but it does not seem to be as significant a problem under GDI+ . To be efficient you can dispose of them after use, or if they are members in your form. > I assume that any += delegate not in the InitializeComponent is up to me to clean up. Just let the GC do it for you Ian Cooper wwww.dnug.org.uk |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

