question about memory leaks in editor
I was doing some work with the memory profiler in Unity.. Basically, I'd launch unity, play in editor in a simple level, stop playing, take a memory snapshot, then play in editor in the same level again, exit, and take a second snapshot. Then I'd compare the two snapshots using the memory profiler.
What I'm seeing in the memory profile is it seems like a lot of Noesis objects are leaking each time I play in editor. For example, in my initial snapshot there were 4,483 instances of "NoesisApp.DataTrigger", and in the second snapshot there were 8,966.
I'm probably just doing something stupid and not shutting things down properly, so these aren't getting cleaned up -- but I'm not sure what exactly I'm missing... or if it's more just a problem with properly disposing my data model or something else.
have y'all ever seen this before, or have suggestions?
thanks,
sam
What I'm seeing in the memory profile is it seems like a lot of Noesis objects are leaking each time I play in editor. For example, in my initial snapshot there were 4,483 instances of "NoesisApp.DataTrigger", and in the second snapshot there were 8,966.
I'm probably just doing something stupid and not shutting things down properly, so these aren't getting cleaned up -- but I'm not sure what exactly I'm missing... or if it's more just a problem with properly disposing my data model or something else.
have y'all ever seen this before, or have suggestions?
thanks,
sam
Re: question about memory leaks in editor
Leaks like this can be caused by references to unmanaged objects in C#.
WeakReferences are needed to avoid this behaviour, you can read about that in our Events Tutorial: https://www.noesisengine.com/docs/Gui.C ... vents-in-c
If you'd like to report an issue, with an attached sample which reproduces this issue, I will look into it.
WeakReferences are needed to avoid this behaviour, you can read about that in our Events Tutorial: https://www.noesisengine.com/docs/Gui.C ... vents-in-c
If you'd like to report an issue, with an attached sample which reproduces this issue, I will look into it.
Re: question about memory leaks in editor
I think the problem is with this static "_extends" dictionary defined in "Extends.cs":
It looks like this is cleared on domain reload, but I don't see that it is being cleared after play in editor mode, which will cause all the objects in it to leak.
Am I missing something?
sam
Code: Select all
private static Dictionary<long, ExtendInfo> _extends = new Dictionary<long, ExtendInfo>();
Am I missing something?
sam
-
-
sfernandez
Site Admin
- Posts: 2794
- Joined:
Re: question about memory leaks in editor
Hi Sam,
It looks like there is some circular reference that produces those memory leaks. In 3.1.6 we did some changes to try to break those circular references that usually occur when a child dependency property stores a reference to a parent, for example if I do:
Are you already using 3.1.6+ version, or still on an older version?
That _extends dictionary is cleared on domain reload as you mentioned, that will happen every time you hit Play if you have the default option selected in Unity (Edit > Project Settings > Editor and Enter Play Mode Options). Anyway, if there are circular references like the ones I described, our native library won't be able to release those objects.
I have access to your repository, so if you point me to a sample scene where I can reproduce this I can take a look to find out the cause of the leak. Please create a private ticket in our bugtracker to better handle this.
It looks like there is some circular reference that produces those memory leaks. In 3.1.6 we did some changes to try to break those circular references that usually occur when a child dependency property stores a reference to a parent, for example if I do:
Code: Select all
<Grid x:Name="grid" Background="Red">
<Rectangle Fill="Blue" Margin="20">
<b:Interaction.Triggers>
<b:EventTrigger SourceObject="{Binding ElementName=grid}" EventName="MouseEnter">
<b:ChangePropertyAction PropertyName="Fill" Value="Green"/>
</b:EventTrigger>
</b:Interaction.Triggers>
</Rectangle>
</Grid>
That _extends dictionary is cleared on domain reload as you mentioned, that will happen every time you hit Play if you have the default option selected in Unity (Edit > Project Settings > Editor and Enter Play Mode Options). Anyway, if there are circular references like the ones I described, our native library won't be able to release those objects.
I have access to your repository, so if you point me to a sample scene where I can reproduce this I can take a look to find out the cause of the leak. Please create a private ticket in our bugtracker to better handle this.
Re: question about memory leaks in editor
We are on 3.1.6 in this test case.That _extends dictionary is cleared on domain reload as you mentioned, that will happen every time you hit Play if you have the default option selected in Unity (Edit > Project Settings > Editor and Enter Play Mode Options). Anyway, if there are circular references like the ones I described, our native library won't be able to release those objects.
We don't do domain reloads when entering play mode because of the performance hit we incur.
Is there a way I could manually clean things up after playing in editor? Would it be safe for me to just call Extend.ClearTables() or would that cause memory leaks on the unmanaged side? If there is some way to shutdown / clean up everything gracefully I can easily add that.
thanks,
sam
-
-
sfernandez
Site Admin
- Posts: 2794
- Joined:
Re: question about memory leaks in editor
If there is no assembly reload then it makes sense that some objects stay alive until the GC collects them, if the objects are not referenced in C++ too. That will mean that there is a circular reference somewhere. As I mentioned before I would like to debug that scenario if you point me how to reproduce it.We don't do domain reloads when entering play mode because of the performance hit we incur.
If you want to cleanup all the instances created in C# you can call Noesis.GUI.UnregisterNativeTypes() to restore everything.Is there a way I could manually clean things up after playing in editor?
Who is online
Users browsing this forum: No registered users and 11 guests