| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
|
April 06, 2008 Proposal: GC and "delete" | ||||
|---|---|---|---|---|
| ||||
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 Re: Proposal: GC and "delete" | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Brian White | 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 Re: Proposal: GC and "delete" | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Gregor Richards | > 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 Re: Proposal: GC and "delete" | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Brian White | == 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 Re: Proposal: GC and "delete" | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Brian White | 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
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply