Skip to content

Memory leak with widgets that have event handlers #254

@gnunn1

Description

@gnunn1

I had a Tilix user report a pretty serious memory leak with the Tilix sidebar here: gnunn1/tilix#1558

After debugging it I've determined that the issue happens when a widget has an event handler associated with it. This seems to prevent the D GC from reclaiming the object and freeing it. If there is no event handlers in the widget everything works fine.

I've created a simple reproducer for you so you don't have to deal with the large Tilix code base to track this down. The reproducer is located here:

https://github.com/gnunn1/gctest

To reproduce the issue, compile the application using the following command:

dub build --config=trace

Notice in the destructor of the ListBoxRow I have added a line to log when the D destructor is called here:

https://github.com/gnunn1/gctest/blob/master/source/gctest.d#L129

After compiling the program run it in a terminal so you can see the output. The application shows a window with a headerbar and a listbox with some rows in it. In the headerbar are two buttons: "Recreate Rows" and "GC". If you click the "Recreate Rows" button it will remove the existing rows and replace them with a new set. Clicking the "GC" button invokes D's GC.

Press the "Recreate Rows" once and then press the "GC" button a couple of times, notice there is no output from the destructor.

Next, comment out the event handler for the button in the GCListBoxRow at line 129 (https://github.com/gnunn1/gctest/blob/master/source/gctest.d#L129) and re-compile it and then run it again. Repeat the same exercise as above and you will see that the destructor is now being invoked.

If you need any additional information just let mw know.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions