custom memory management

Dicebot public at dicebot.lv
Fri Feb 28 04:54:30 PST 2014


On Friday, 28 February 2014 at 12:36:48 UTC, Simon Bürger wrote:
> If you are right that would mean that the current dmd/runtime 
> does not follow the spec. Curious. The current implementation 
> is not aware of strcut-destructors on the heap, i.e. the 
> GC.BlkAttr.FINALIZE flag is not set for structs (or arrays of 
> structs).

Ah, structs are a bit tricky. Spec has override for struct 
destructors that says explicitly "Destructors are called when an 
object goes out of scope" so one can argue heap ignorance matches 
it. But the very next line contradicts it : "Their purpose is to 
free up resources owned by the struct object".

I believe it is a DMD bug though. There is no reason why 
destructors can't be run here. Most likely it is just defect of 
current GC implementation that everyone got used to.

This bug report discussion confirms it : 
https://d.puremagic.com/issues/show_bug.cgi?id=2834

Looks like decision was to fix it once precise GC gets added.

> In the struct-inside-a-class example, the struct destructor is 
> called by the (automatically generated) class-destructor. The 
> gc only knows about class-destructor and calls only that one 
> directly.

Yes, that matches my current observations. Did not occure before 
because of C coding habits :) Lucky me.


More information about the Digitalmars-d-learn mailing list