GC.collect bug ?

evilrat evilrat666 at gmail.com
Fri Sep 13 09:40:03 PDT 2013


On Friday, 13 September 2013 at 15:24:17 UTC, Temtaime wrote:
> Hello for all !
>
> I need to call all objects destructors in one place.
> It's guaranted, that there is no objects instances.
>
> I tried use GC.collect but it's produces strange results.
>
> import std.stdio;
> import core.memory;
>
> class A {
> 	~this() { writeln(`dtor`); };
> };
>
> void main() {
> 	auto a = new A;
> 	a = null;
>
> 	GC.collect();
> 	writeln(`after dtor`);
> }
>
> Output is:
> after dtor
> dtor
>
> Why?
>
> Regards.

this is probably because nothing collected until reference in 
main function goes from scope. last time i tried GC.collect it 
wasn't do immediate GC run, AFAIK you can't force it to do so in 
predictable manner.


More information about the Digitalmars-d-learn mailing list