Thanks for replying but your provided reason somehow doesn't convince me
that it's the case for strings. I thought it was that simple too until I
read this part of
http://msdn.microsoft.com/msdnmag/issues/1100/gci/: The
runtime doesn't make any guarantees as to the order in which Finalize
methods are called. For example, let's say there is an object that contains
a pointer to an inner object. The garbage collector has detected that both
objects are garbage. Furthermore, say that the inner object's Finalize
method gets called first. Now, the outer object's Finalize method is allowed
to access the inner object and call methods on it, but the inner object has
been finalized and the results may be unpredictable. For this reason, it is
strongly recommended that Finalize methods not access any inner, member
objects.
Any other comments and suggestions? thanks!
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:Ou**************@TK2MSFTNGP02.phx.gbl...
Hi,
The finalizer is intended to be used to cleanup unmanaged resources, these
resources need to be kept referenced in the class, in short, yes, you can
use the member variables inside the finalizer.
I suggest you to take a look at the IDisposable interface though.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Zen" <ze*@nononospam.com> wrote in message
news:eE****************@TK2MSFTNGP02.phx.gbl... Hi,
Is my finalizer safe? Thanks!!
public class MyClass
{
private string m_str;
public MyClass( string s )
{
m_str = s;
}
~MyClass()
{
// is this safe?
if( m_str == "blah" )
// do something ;
}
}