GC and dtors ~ a different approach?
kris
foo at bar.com
Thu Apr 13 10:54:35 PDT 2006
Bruno Medeiros wrote:
> kris wrote:
>
>> Bruno Medeiros wrote:
>>
>>>
>>>
>>> All of those pros you mention are valid. But you'd have one serious con:
>>> * Any class which required cleanup would have to be manually memory
>>> managed.
>>>
>>
>
> Just one addendum: I was just pointing out that con, I wasn't saying it
> was or was not, a bad idea overall.
>
>>
>> First, let's change the verbiage of "valid" and "unspecified" to be
>> "deterministic" and "non-deterministic" respectively (per Don C).
>>
>
> Let's not. *g* See my reply to the Don.
heheh :)
>
>>
>> To get to your assertion: under the suggested model, any class with
>> resources that need to be released should either be 'delete'd at some
>> appropriate point, or have raii applied to it. Classes with dtors that
>> are not cleaned up in this manner can be treated as "leaks" (and can
>> be identified at runtime).
>>
>> Thus, the term "manually memory managed" is not as clear as it might
>> be: raii can be used to clean up, and scope(exit) can be used to
>> cleanup. An explicit 'delete' can be used to cleanup. There's no
>> malloc() or anything like that invoved.
>>
>
> Those are all manual memory management. (Even if auto and scope() are
> much better than plain malloc/free).
> [Note: RAII's auto = scope(exit)]
> You would have an automatic leak/failure detection, true.
>
>> The truly serious problem with a 'lazy' cleanup is that the dtor will
>> wind up invoked with non-determinstic state (typically leading to a
>> serious error). The other concern with lazy cleanup is what Mike
>> addresses (if the resource needs cleaning up, it should be done in a
>> timely manner ~ not at some arbitrary point in the future).
>>
>
> The state is *undefined*, it is not "non-deterministic" nor
> "deterministic". This is the kind of terminology blur up that I was
> leery of. :P
:-D
Terminology aside; with the current implementation, invocation of dtors
during a collection often causes serious problems. That's why we see the
use of close/dispose patterns in D. It would be great to avoid both of
those things :p
More information about the Digitalmars-d
mailing list