[Issue 9900] New: static this and gc shutdown order issue

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 7 15:17:17 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9900

           Summary: static this and gc shutdown order issue
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: nobody at puremagic.com
        ReportedBy: flamaros.xavier at gmail.com


--- Comment #0 from Xavier Bigand <flamaros.xavier at gmail.com> 2013-04-07 15:17:16 PDT ---
It seems gc is called after the main function to release all allocation, but
only after all static this method were called.

I get a crash when my application is shutting down because Derelict library use
static this methods to unload dynamic libraries, but I have to use some
functions of those dynamic libraries to release their objects. I call libraries
shutting down functions in classes destructors which are called after the
dynamic libraries were unloaded.

Pseudo code :

// main.d
main()
{
   DerelictLua.load();    // Load lua library and affect all lua functions ptr

   LuaContext script = new LuaContext();

   return script.execute();
}

static ~this()
{
    DerelictLua.unload();    // Unload the liblua.so or dll, first
}

// luaContext.d
class LuaContext
{
    this()
    {
        mLuaContext = lua_newstate();
    }

    ~this()
    {
        lua_close(mLuaContext);    // Release the main lua library object,
second (lua_close is now a bad pointer)
    }

    Lua_State* mLuaContext;
}


I am expecting because the "script" variable isn't use out from the "main"
function scope having no issue of this kind.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list