DMD dll GC bug when calling a function from an interface that creates a new object

Hipreme msnmancini at hotmail.com
Thu Oct 27 02:42:47 UTC 2022


I have some sample code:


```d
interface IFont
{
   IFont createFontWithSize(int size);
}
```

Main Code:

```d
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:

```d
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



More information about the Digitalmars-d mailing list