GC and dtors ~ a different approach?

kris foo at bar.com
Mon Apr 10 13:29:56 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.  

Aye


> 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.

Yes; that's how I feel about it also. Especially when the "silent" 
cleanup leads to SegFaults and such. Intended as a fail-safe, but 
actually a failure-causation ;-)



More information about the Digitalmars-d mailing list