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

Exception Handling and Garbage Collection

P: n/a
a.. In Java, GC.Collect schedules the collection. As far as I know, in
..NET, it runs immediately after calling the method. Is that right?
b.. Should I use exception handling (try-catch) to avoid inconsistencies
that can occur in the Dispose method? For example, a connection is closed,
and then an error occurs and GC.SuppressFinalize is not executed. When GC
runs, it tries to close the connection again by calling the Dispose method
from Finalize.
c.. Is there a CATCH WHEN in C# to catch errors raised by a COM component
(err.raise)?
thanks again.
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Marcelo,

a) GC.Collect requests that a garbage collection is executed, but that's not
guaranteed. For example, if the GC is in the middle of a collection when
GC.Collect is called, it won't be executed again. Also, calling GC.Collect
is normally a bad practice, because the GC has a much better understanding
of the local environment.

b) Yes, I use Try...Catch to handle problems within my Dispose methods (and
also in my Finalize methods).

c) No, CATCH WHEN... is a trick reserved for VB .NET.

HTH,

Mark
--
Author of "Comprehensive VB .NET Debugging"
http://www.apress.com/book/bookDisplay.html?bID=128
"J. Marcelo Barbieri" <mb*******@bf.com.br> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
a.. In Java, GC.Collect schedules the collection. As far as I know, in
..NET, it runs immediately after calling the method. Is that right?
b.. Should I use exception handling (try-catch) to avoid inconsistencies
that can occur in the Dispose method? For example, a connection is closed,
and then an error occurs and GC.SuppressFinalize is not executed. When GC
runs, it tries to close the connection again by calling the Dispose method
from Finalize.
c.. Is there a CATCH WHEN in C# to catch errors raised by a COM component
(err.raise)?
thanks again.

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.