new returning the same memory....

Daniel Kozak kozzi11 at gmail.com
Thu Nov 8 12:24:40 UTC 2018


Did you try disable gc?
import core.memory : GC;
GC.disable;
aclass a = new aclass();

I believe that your aclass go out of scope and there is no active reference
to this so GC can collected it and reuse its memory

On Thu, Nov 8, 2018 at 12:50 PM Codifies via Digitalmars-d-learn <
digitalmars-d-learn at puremagic.com> wrote:

> On Thursday, 8 November 2018 at 11:46:44 UTC, Codifies wrote:
> > when creating a new instance of a class
> >
> > aclass a = new aclass();
> >
> > I was under the impression that this created a new chunk of
> > memory on the heap...
> >
> > however I'm trying to create this class instance in another
> > classes method, I also need to store a pointer to this newly
> > created instance in the same method.
> >
> > when I look at the actual value of the pointer, although it
> > does change after multiple goes, frequently its the same value.
> >
> > It almost looks like its allocating on the local stack and its
> > made a new instance thats entirely local to the factory method.
> >
> > do I need to manually allocate the memory ?? how do I do this?
> > how can I allow the GC to clean this up?
> >
> > I'm *really* discombobulated now, as new doesn't seem to be
> > working how I thought it did!!!
>
> I'll try to spin up a minimal example...
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20181108/969a3e0b/attachment.html>


More information about the Digitalmars-d-learn mailing list