AdaptiveTriggerLibrary icon indicating copy to clipboard operation
AdaptiveTriggerLibrary copied to clipboard

Potential memory leak with Modifiers when added as Resources to individual pages

Open JSmyth886 opened this issue 9 years ago • 2 comments

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>

JSmyth886 avatar Dec 21 '16 11:12 JSmyth886

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?

Herdo avatar Dec 27 '16 11:12 Herdo

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.

JSmyth886 avatar Feb 15 '17 06:02 JSmyth886