digitalmars.D - Proposal: GC and "delete"
- Brian White (7/7) Apr 05 2008 Would it be possible to add a lightweight flag to the GC module to
- Gregor Richards (6/15) Apr 06 2008 The only time you would have user code running while the GC is running
- Brian White (7/11) Apr 06 2008 Which was exactly the problem I was trying to address. Sometimes (like
- Unknown W. Brackets (5/19) Apr 06 2008 IMHO, the simple solution to this is an "opDelete" which gets called
- Sean Kelly (3/9) Apr 06 2008 This could be done in Tango via the collectHandler. Check out tango.cor...
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
Apr 05 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. -- BrianThe 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
Apr 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
Apr 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
Apr 06 2008
== Quote from Brian White (bcwhite pobox.com)'s articleWould 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
Apr 06 2008