www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - gc_term() memory leaking.

reply Neal Alexander <wqeqweuqy hotmail.com> writes:
Is there any way to force a GC instance in a DLL to free the heap pages 
allocated by gc_init? gc_term()is just an alias to fullCollectNoStack().

the following DLL leaks around 1,000-2,000K each time the dll is reloaded.

extern (Windows):
BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved)
{

     g_hInst = hInstance;

     switch (ulReason){
     case DLL_PROCESS_ATTACH:

         gc_init();
         _minit();
         _moduleCtor();

	activate();
	break;

     case DLL_PROCESS_DETACH:

         _moduleDtor();
         gc_term();
         break;

     case DLL_THREAD_ATTACH:
     case DLL_THREAD_DETACH:

         return false;
     }

     return TRUE;
}
Jul 07 2007
parent reply Paul Findlay <r.lph50+d gmail.com> writes:
 Is there any way to force a GC instance in a DLL to free the heap pages
 allocated by gc_init? gc_term()is just an alias to fullCollectNoStack().
Tango's gc_term() call's a destructor which frees the calloc'ed heap. But sorry, I don't know much more than that.. - Paul
Jul 07 2007
parent Neal Alexander <wqeqweuqy hotmail.com> writes:
Paul Findlay wrote:
 Is there any way to force a GC instance in a DLL to free the heap pages
 allocated by gc_init? gc_term()is just an alias to fullCollectNoStack().
Tango's gc_term() call's a destructor which frees the calloc'ed heap. But sorry, I don't know much more than that.. - Paul
Alright, well i added this to src/phobos/internal/gc.d and rebuilt phobos.lib. extern (C) void gc_destroy(){ _gc.Dtor(); } And added gc_destroy() to the unload section of DllMain. Looks like it solved the problem somewhat - it only leaks 100kb now when the DLL reloads instead of 1.5mb. That 100kb could easily be the fault of my program too; i'm not sure atm. Should i file a bug report about this or what? Its possible gc_term()'s behavior has been the same ever since the start. I'm using DMD2.02 if i haven't mentioned it already.
Jul 08 2007