GC and dtors ~ a different approach?
Sean Kelly
sean at f4.ca
Mon Apr 10 12:57:37 PDT 2006
kris wrote:
> Bruno Medeiros wrote:
>> kris 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.
>
> Can anyone come up with some examples whereby a class needs to cleanup,
> and also /needs/ to be collected lazily? In other words, where raii or
> delete could not be applied appropriately?
Well, there are plenty of instances where the lifetime of an object
isn't bound to a specific owner or scope--consider connection objects
for a server app. However, in most cases it's possible (and correct) to
delegate cleanup responsibility to a specific manager object or to link
it to the occurrence of some specific event. So far as
non-deterministic cleanup via dtors is concerned, I think it's mostly
implemented as a fail-safe. And it may be more correct to signal an
error if such an object is encountered via a GC run than to simply clean
it up silently, as a careful programmer might consider this a resource leak.
Sean
More information about the Digitalmars-d
mailing list