How to force D GC to deallocate everything?

Clipsey clipsey at librem.one
Fri Jun 14 08:15:20 UTC 2019


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;
}


More information about the Digitalmars-d-learn mailing list