Beef
Beef copied to clipboard
GC detects leaks for items that are added to the List field of the base class, when the class scope allocated.
I have a base class that defines append list and derived class that have a method that allocates new items and adds it to the list. However, after allocating the class on stack and calling that method, after a few seconds GC detects memory leaks, even though the list field has a destructor that deletes all items.
Code example
class Program
{
static int Main(String[] args)
{
var test = scope Test2();
test.AddItems();
while(true)
{
Thread.Sleep(500);
}
}
}
class Test1
{
public append List<TestItem> Items ~ ClearAndDeleteItems!(_);
}
class Test2 : Test1
{
public void AddItems()
{
Items.Add(new TestItem());
Items.Add(new TestItem());
}
}
class TestItem {}
Output: