PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms What do I need to clean up in dispose?

Reply

What do I need to clean up in dispose?

 
Thread Tools Rate Thread
Old 25-06-2003, 03:00 PM   #1
Kevin Peck
Guest
 
Posts: n/a
Default What do I need to clean up in dispose?


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.
  Reply With Quote
Old 25-06-2003, 04:17 PM   #2
Ian Cooper
Guest
 
Posts: n/a
Default Re: What do I need to clean up in dispose?

> 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
  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off