How to use destroy and free.

Alain De Vos devosalain at ymail.com
Mon Apr 25 10:13:43 UTC 2022


Ali, thanks for the answer but i rephrase my question.
How to destroy,free , for garbage-collection-cycle in the 
destructor of this code :

```
import std.stdio: writeln;

class C{
	int[] i=null;
	this(){
		writeln("Allocate heap");
		i=new int[10000];
		writeln(typeid(typeof(i)));
		writeln(typeid(typeof(i.ptr)));
		i[9000]=5;
	}
	~this(){
		writeln("Free heap");
		import object: destroy;
		import core.memory: GC;
		i=null;
                 // But How to force destroy and free , GC-cycle 
for heap object i ?
	};
}

struct S{
	C c;
	@disable this();
	this(int dummy){c=new C;}
}

void main(){
	enum _=0;
	writeln(S(_).c.i[9000]);
}
```


More information about the Digitalmars-d-learn mailing list