I have some sample code:
interface IFont
{
IFont createFontWithSize(int size);
}
Main Code:
import common;
class TTFFont : IFont
{
IFont createFontWithSize(int size){return new TTFFont;}
}
export extern(System) IFont newFont()
{
auto ret = new TTFFont();
GC.addRoot(ret);
return ret;
}
DLL Code:
import common;
Runtime.initialize();
IFont function() newFont;
newFont = loadSymbol("newFont");
IFont myFont = newFont();
IFont otherFont = myFont.createFontWithSize(32); //Gets collected after some time
For it not get collected after some time, I actually need to put GC.addRoot inside the function createFontWithSize
. This makes it literally unusable