Potential memory leak with Modifiers when added as Resources to individual pages
Not sure if this is an issue or not with the library, but I was seeing lots of memory leaks in my apps Views. Turned out it was the Modifiers being held onto by each Page and never releasing them for GC. A workaround to this issue I found was to set your Modifiers in the Applications resources like below:
<Application.Resources>
<ResourceDictionary>
<logicalModifiers:OrModifier x:Key="OrModifier" />
<logicalModifiers:AndModifier x:Key="AndModifier" />
<comparableModifiers:LessThanModifier x:Key="LessThanModifier" />
<comparableModifiers:LessThanEqualToModifier x:Key="LessThanEqualToModifier" />
<comparableModifiers:GreaterThanEqualToModifier x:Key="GreaterThanEqualToModifier" />
<!-- Similar to how you would add a Converter globally like below -->
<converters:BooleanToCollapsedConverter x:Key="BooleanToCollapsedConverter" />
</ResourceDictionary>
</Application.Resources>
Hey @JSmyth886 , could you please provide some code about the page and it's access?
I'm only guessing:
- You have a frame
- Each time you access the "same" page, a new instance of that page is initialized
- Each time you initialize the new page, the ressources are loaded
Are the pages cleared from the BackStack of the frame?
Hi @Herdo, sorry its taken me so long to write back. Been super busy.
The page, its access etc. are set up exactly like your samples. However we use a MVVM framework called Caliburn.
3 yeses to your bullet points.
In answer to your question, the pages are cleared from the BackStack of the frame. But references are still held to the Modifiers which in turn leads to a memory leak for that page. Albeit a rather minor memory leak.