Writing a library

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Sat Feb 17 04:00:32 PST 2007


Mn wrote:
> 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 ________ ?

It's a static variable in a DLL, so it stays in memory from the time the 
DLL is loaded to when it's unloaded (which may be at application 
shutdown if it's never explicitly unloaded).



More information about the Digitalmars-d mailing list