[Mono-list] Accessing member objects in destructors

Uppenborn, Jason Jason.Uppenborn@atcoitek.com
Thu, 4 Mar 2004 13:01:32 -0700


Hi Gustavo

Did you mean object destructor or did you really mean a class =
destructor?

For a *class* destructor, I would say that accessing methods of member =
objects would be correct because, AFAIK, as there isn't any other point =
at which the class is told to release it's resources.

For an *object* destructor, I would say that accessing methods of member =
objects is incorrect: implement IDisposable instead. As I understand it, =
disposal happens as requested or when an object is made available for =
garbage collection, whereas destruction is done whenever the garbage =
collector decides to get around to it. When destruction happens, you =
have no guarantee that any of your references to member objects are =
still valid.

I'm sure someone will correct me if I'm wrong, but for now that's my two =
cents.

Jason


-----Original Message-----
From: mono-list-admin@lists.ximian.com =
[mailto:mono-list-admin@lists.ximian.com] On Behalf Of Gustavo Garc=EDa =
Bernardo
Sent: Thursday, March 04, 2004 10:24 AM
To: mono-list@ximian.com
Subject: [Mono-list] Accessing member objects in destructors

Hi,
Reading the Mono code i have seen sometimes a class destructor access a
method of a member object:

Socket socket =3D new Socket();
~XXXX
{
	socket.Close ();
}

Is this correct? You can assert the socket object is not freed before =
XXX
object?

Thx, best regards.

G.

_______________________________________________
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list