How to free memory ater use of "new" to allocate it.
Ernesto Castellotti
erny.castell at gmail.com
Mon Jul 17 22:54:09 UTC 2023
On Monday, 17 July 2023 at 16:52:00 UTC, Alain De Vos wrote:
> This works also,
>
>
> ```
>
> class C {
> int * pa;
> int [] a;
> // Constructor
> this() {writefln("Called constructor");
> pa=cast(int *)malloc(1000*int.sizeof);
> a=pa[0..1000];
> }
>
> }
>
> void dofun()
> {
> scope x=new C;
> x.a[3]=5;
> writefln("%12x",&x);
>
> }
> int main(){
> dofun();
> dofun();
> return 0;
>
> }
>
> ```
Remember to use free, this is not managed by the GC
More information about the Digitalmars-d-learn
mailing list