By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,639 Members | 2,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,639 IT Pros & Developers. It's quick & easy.

When to call dispose()?

P: n/a
Hi,
I have a form containing controls, a timer, and the EventLog component.
I also create some new instances of classes that do not implement idisposable
I don't want to leave the tidying up to the GC so...
Do I need to explicitly call EventLog.dispose() as in the following snippet?

protected overloads sub dispose(byval disposing as boolean)
if disposing
if components is nothing then
components.dispose
end if
call MyEventLog.dispose(True) <<<--
end if
end sub

Also how do I make sure that the classes that don't implement idisposable return their memory one I've finished.Do I just close them, or set them to nothing, or what?

Help much appreciated
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Cor
Hi Nigel,

My idea is that if not is strictly written in the documentation that
something has to be disposed (by instance large bitmaps) not to do it.

It cannot be else than that a dispose takes some action, so let it be done
in one cleansweep at the end.

My idea about it is the same as closing a book, what I opens a lot of times
again and dispose when I never read it again.

Cor
I have a form containing controls, a timer, and the EventLog component.
I also create some new instances of classes that do not implement idisposable I don't want to leave the tidying up to the GC so...
Do I need to explicitly call EventLog.dispose() as in the following snippet?
protected overloads sub dispose(byval disposing as boolean)
if disposing
if components is nothing then
components.dispose
end if
call MyEventLog.dispose(True) <<<--
end if
end sub

Also how do I make sure that the classes that don't implement idisposable

return their memory one I've finished.Do I just close them, or set them to
nothing, or what?
Jul 21 '05 #2

P: n/a

Nigel why dont you want to leave memory reclaimation to the GC? The purpose of IDisposable is to A: allow you to dispose in a neat fashion, and B: to indicate to the class consumer that the class has resources that should be released at the earliest convenience - such as file handles, DB connections etc. In all other cases it is best to leave the memory to the GC. Even if IDisposable.Dispose is invoked, the object itself is still left to GC collection at some other time. Also look at overriding Finalize. To instigate a memory collection, call GC.Collect();

Nick.

----- Nigel T wrote: -----

Hi,
I have a form containing controls, a timer, and the EventLog component.
I also create some new instances of classes that do not implement idisposable
I don't want to leave the tidying up to the GC so...
Do I need to explicitly call EventLog.dispose() as in the following snippet?

protected overloads sub dispose(byval disposing as boolean)
if disposing
if components is nothing then
components.dispose
end if
call MyEventLog.dispose(True) <<<--
end if
end sub

Also how do I make sure that the classes that don't implement idisposable return their memory one I've finished.Do I just close them, or set them to nothing, or what?

Help much appreciated
Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.