Endlessly increasing memory allocations
I'm finding a steadily increasing amount of allocated memory by Noesis (3.2.7) between multiple matches in my Unity app for Meta Quest (Android).
There's several world space UIs, but they (the NoesisWorldUi's) along with the NoesisView are all destroyed at the end of each program state.
That is, they are created for the main menu, then destroyed when going into a match. They are then created within a match, and destroyed at the end of the match.
In one series of tests, after swapping between some menu scenes, the memory had reached this point by the start of the first match:
Accumulated: 265047320
Current: 21140344
Allocs: 983074
By the start of the second:
Accumulated: 332761976
Current: 21948936
Allocs: 1448473
By the start of the third:
Accumulated: 399827368
Current: 22387264
Allocs: 1910425
These values have been sampled with
Noesis.Memory.Accumulated
Noesis.Memory.Current
Noesis.Memory.Allocs
There's very little going on beyond the basic Noesis functionality here. Loading of xaml's/etc. is done by Noesis within the provided Unity components (NoesisWorldUi, NoesisView), so I can't intuitively see any opportunity for me to be doing anything differently.
I've also subscribed to logs. I'm not sure what to expect, but something I have noticed is that xaml's are loaded several times over. There's no sign of any "unload" logs.
Is there any guidance on how to go about debugging this problem space, or documentation regarding cleaning up UI's that I am missing (rather than just destroying their game objects?).
Thank you.
There's several world space UIs, but they (the NoesisWorldUi's) along with the NoesisView are all destroyed at the end of each program state.
That is, they are created for the main menu, then destroyed when going into a match. They are then created within a match, and destroyed at the end of the match.
In one series of tests, after swapping between some menu scenes, the memory had reached this point by the start of the first match:
Accumulated: 265047320
Current: 21140344
Allocs: 983074
By the start of the second:
Accumulated: 332761976
Current: 21948936
Allocs: 1448473
By the start of the third:
Accumulated: 399827368
Current: 22387264
Allocs: 1910425
These values have been sampled with
Noesis.Memory.Accumulated
Noesis.Memory.Current
Noesis.Memory.Allocs
There's very little going on beyond the basic Noesis functionality here. Loading of xaml's/etc. is done by Noesis within the provided Unity components (NoesisWorldUi, NoesisView), so I can't intuitively see any opportunity for me to be doing anything differently.
I've also subscribed to logs. I'm not sure what to expect, but something I have noticed is that xaml's are loaded several times over. There's no sign of any "unload" logs.
Is there any guidance on how to go about debugging this problem space, or documentation regarding cleaning up UI's that I am missing (rather than just destroying their game objects?).
Thank you.
-
- ttermeer-reboundcg
- Posts: 31
- Joined:
- Contact:
Re: Endlessly increasing memory allocations
You can use Unity memory profiler to check if your UI classes are still in memory and then hunt down any references.
Common issue is reference held by events.
Common issue is reference held by events.
Re: Endlessly increasing memory allocations
Also make sure to update to 3.2.10 (or wait a bit for 3.2.11), we fixed a few things regarding memory usage in C# bindings.
Re: Endlessly increasing memory allocations
Thanks both for the quick responses already.
I've done some extensive memory profiling today.
I've got no NoesisWorldUis or NoesisViews hanging around beyond their expended lifetime.
I can't find anything to suggest the game code is holding onto noesis references.
I can see an increasing amount of ExtendInfo within the Extend classes static dictionary.
Allocs went up nearly 1 million between these two memory snapshots.
I'll need to try a version update, but if there is any known issue or workaround that'd be great.
Or, specific keywords for me to look into in the memory profiler that I may have missed?
I've done some extensive memory profiling today.
I've got no NoesisWorldUis or NoesisViews hanging around beyond their expended lifetime.
I can't find anything to suggest the game code is holding onto noesis references.
I can see an increasing amount of ExtendInfo within the Extend classes static dictionary.
Allocs went up nearly 1 million between these two memory snapshots.
I'll need to try a version update, but if there is any known issue or workaround that'd be great.
Or, specific keywords for me to look into in the memory profiler that I may have missed?
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Endlessly increasing memory allocations
The main source of memory leaks in C# is event handlers. If a control subscribes to an event and the the handler references the control itself, then the delegate keeps a reference to the control and then it will never be released. You should use a weak event registration to avoid this:
Could you check that?
Code: Select all
public MainWindow()
{
// Break circular reference using a WeakReference as intermediary
WeakReference weak = new WeakReference(this);
this.MouseDown += (s, e) => { ((MainWindow)weak.Target)?.OnMouseDown(s, e); };
this.MouseUp += (s, e) => { ((MainWindow)weak.Target)?.OnMouseUp(s, e); };
this.MouseMove += (s, e) => { ((MainWindow)weak.Target)?.OnMouseMove(s, e); };
this.InitializeComponent();
}Re: Endlessly increasing memory allocations
We really don't have much going on in the control level other than the basic noesis boilerplate.
I searched through, but couldn't find anything that fits this criteria.
Most of our dynamic features are bound to ReactiveCommand or BindableReactiveProperty from the R3 library (https://github.com/c9s/r3)
These are disposed of, and I can't find any managed references of our view models remaining.
I'm going to try updating Noesis now, to see if there's any improvements.
I searched through, but couldn't find anything that fits this criteria.
Most of our dynamic features are bound to ReactiveCommand or BindableReactiveProperty from the R3 library (https://github.com/c9s/r3)
These are disposed of, and I can't find any managed references of our view models remaining.
I'm going to try updating Noesis now, to see if there's any improvements.
Who is online
Users browsing this forum: Bing [Bot] and 4 guests