What's the use case of clear?

Jonathan M Davis jmdavisprog at gmail.com
Tue Aug 10 10:16:31 PDT 2010


On Tuesday, August 10, 2010 08:09:13 Steven Schveighoffer wrote:
> But we should clarify a couple things.  First, destructors are *only*
> valid for releasing resources not allocated by the GC.  For example, in
> your Connection object, if you used a phobos object to make the
> connection, and allocated that connection via new, then you are *not*
> guaranteed that the GC hasn't collected that object already.  So it is not
> valid in the destructor.

Hmm. I don't recall ever reading that anywhere. I would not have expected 
anything that was referenced by an object to be garbage collected until the 
destructor had been called on that object. Granted, the need for destructors on 
classes is minimal, but that seems like the kind of thing that should be in big 
red lettering somewhere. You just know that there are going to be plenty of 
programmers out there who are going to referencing newed data in the destructor. 
It's a very natural thing to do for cleanup if you have object references as 
member data.

- Jonathan M Davis


More information about the Digitalmars-d mailing list