Writing a library

Mn mn at mailinator.com
Sat Feb 17 03:40:37 PST 2007


Jarrett Billingsley Wrote:

One way of doing this for classes is to keep a 
> static list or AA of all instances of the class in the class:
> 
> class ExportedClass
> {
>     static bool[ExportedClass] instances;
> 
>     this()
>     {
>         ....
>         instances[this] = true;
>     }
> 
>     ~this()
>     {
>         instances.remove(this);
>     }
> }
> 

But now if I somehow call a create()-function (or however i call it) it creates a class instance and returns it. The class adds a reference to that instance to its instances list. But then we return from that create() function to the program outside of the lib/dll - and the instances list? Doesnt it get removed by GC? How long does it (the instances list) stay in memory (or wherever it is)? From first call to OS shutdown? Or to host app shutdown? Or to ________ ?

--Mn



More information about the Digitalmars-d mailing list