www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to force D GC to deallocate everything?

I have written an DLL in D which gets used by an application 
(written in C)
When the C code tries to deallocate/close the DLL, the C 
application freezes and/or leaks memory.

My profiling using AMD ┬ÁProf tells me that the D DLL never gets 
closed, my guess is that the D GC never deallocates everything 
(even though i've put destroy() in every destructor and run 
GC.collect() before DLL close)

My DllMain implementation:

module dllroot;
import implementation;
import core.sys.windows.windows;
import core.sys.windows.dll;
import core.runtime;

__gshared HINSTANCE g_hInst;

extern (Windows)
BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID 
pvReserved)
{
     switch (ulReason)
     {
	case DLL_PROCESS_ATTACH:
	    g_hInst = hInstance;
	    dll_process_attach( hInstance, true );
             initSelf();
	    break;

	case DLL_PROCESS_DETACH:
             prepExit();
             destroy(g_hInst);
	    dll_process_detach( hInstance, true );
             break;

	case DLL_THREAD_ATTACH:
	    dll_thread_attach( true, true );
	    break;

	case DLL_THREAD_DETACH:
	    dll_thread_detach( true, true );
	    break;

         default:
     }
     return true;
}
Jun 14 2019