Thread overview
Proposal: GC and "delete"
Apr 06, 2008
Brian White
Apr 06, 2008
Gregor Richards
Apr 06, 2008
Brian White
Apr 06, 2008
Sean Kelly
April 06, 2008
Would it be possible to add a lightweight flag to the GC module to detect if the GC was currently running?  That would allow an object to conditionally delete sub-objects only if it was safe to do so (i.e. only if not being deleted by the GC).

Alternatively, the "delete" could just do nothing at all during a GC pass.  This would probably be the safest solution.

-- Brian
April 06, 2008
Brian White wrote:
> Would it be possible to add a lightweight flag to the GC module to detect if the GC was currently running?  That would allow an object to conditionally delete sub-objects only if it was safe to do so (i.e. only if not being deleted by the GC).
> 
> Alternatively, the "delete" could just do nothing at all during a GC pass.  This would probably be the safest solution.
> 
> -- Brian

The only time you would have user code running while the GC is running is in a destructor, and you shouldn't be accessing heap objects that potentially need to be deleted from the destructor anyway, since the order of destruction is unpredictable.

 - Gregor Richards
April 06, 2008
> The only time you would have user code running while the GC is running is in a destructor, and you shouldn't be accessing heap objects that potentially need to be deleted from the destructor anyway, since the order of destruction is unpredictable.

Which was exactly the problem I was trying to address.  Sometimes (like with RAII), you want an object destructed when it goes out of scope and if that object contains other RAII objects, they must be deleted/destructed, too.

However, I think I've got a better idea.  Give me some time to write it up...

-- Brian
April 06, 2008
== Quote from Brian White (bcwhite@pobox.com)'s article
> Would it be possible to add a lightweight flag to the GC module to
> detect if the GC was currently running?  That would allow an object to
> conditionally delete sub-objects only if it was safe to do so (i.e. only
> if not being deleted by the GC).
> Alternatively, the "delete" could just do nothing at all during a GC
> pass.  This would probably be the safest solution.

This could be done in Tango via the collectHandler.  Check out tango.core.Runtime.


Sean
April 06, 2008
IMHO, the simple solution to this is an "opDelete" which gets called when and only when "delete x;" is used (afterward delete would be called as standard.)

-[Unknown]


Brian White wrote:
>> The only time you would have user code running while the GC is running is in a destructor, and you shouldn't be accessing heap objects that potentially need to be deleted from the destructor anyway, since the order of destruction is unpredictable.
> 
> Which was exactly the problem I was trying to address.  Sometimes (like with RAII), you want an object destructed when it goes out of scope and if that object contains other RAII objects, they must be deleted/destructed, too.
> 
> However, I think I've got a better idea.  Give me some time to write it up...
> 
> -- Brian