urho icon indicating copy to clipboard operation
urho copied to clipboard

Potential memory leak in UrhoSurface WPF binding

Open jonaspegerfalk opened this issue 7 years ago • 3 comments

I have a simple test app (see https://github.com/jonaspegerfalk/UrhoSharp.TestMemoryLeak) that switches between two user controls, one empty and one with a UrhoSurface WPF element as below. No more Urho magic is initiated in the test app.

<UserControl x:Class="UrhoTestApp.UserControl2"
...
>
    <Grid x:Name="Grid1">
        <TextBlock>User control 2</TextBlock>
        <wpf:UrhoSurface x:Name="Urho1">
        </wpf:UrhoSurface>
    </Grid>
</UserControl>

The user can switch between the two user controls and a new instance of the user controls is created when the user switches to it. The previously visible user control is then removed from the visual tree.

The potential memory leak

This works perfectly fine with the empty user control everything is cleared up when switching away from it. But the second one, with the UrhoSurface object, does not work correctly. The UrhoSurface object is never garbage collected and after a while there will be lots of UrhoSurface objects in memory.

Below is a dependency graph from ANTS memory profiler and it seems like there is something in the input event handling that keeps a reference to the UrhoSurface preventing it from being garbage collected.

memoryleak_testapp

jonaspegerfalk avatar Mar 08 '18 12:03 jonaspegerfalk

Wow, thanks for such a nice bug report 🙂

EgorBo avatar Mar 08 '18 12:03 EgorBo

The text in the image is super tiny.

andrekoehler avatar Mar 08 '18 13:03 andrekoehler

Here is the image as a PDF, which is a bit easier to read :-)

memoryleak_testapp.pdf

jonaspegerfalk avatar Mar 09 '18 07:03 jonaspegerfalk