GC and dtors ~ a different approach?

Georg Wrede georg.wrede at nospam.org
Mon Apr 10 16:52:19 PDT 2006


Sean Kelly wrote:
> 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.

Writing this kind of code demands that the programmer keeps (in his 
mind) a clear picture of _who_ owns the instance.

Getting that unclear is a sure receipe for disaster.



More information about the Digitalmars-d mailing list