UWP DataTemplate LoadContent has memory leak when the template root element is not a framework control

h82258652 1 Reputation point
2022-08-16T01:25:12.863+00:00

Describe the bug

When calling
DataTemplate.LoadContent
, the memory will leak if the root element is not a framework control.

Steps to reproduce the bug

I create a repro demo here: https://github.com/h82258652/UWPDataTemplateLoadContentLeak

  1. Launch demo.
  2. Click the FrameworkTemplate button.
  3. Click the GC collect button.
  4. Click the Show alive count button, it should display Alive reference count: 0.
  5. Click the UserControlTemplate button.
  6. Click the GC collect button.
  7. Click the Show alive count button, it should display Alive reference count: 100.
  8. Click the FrameworkControlHostUserControlTemplate button.
  9. Click the GC collect button.
  10. Click the Show alive count button, it should display Alive reference count: 0.

Expected behavior

The seven step should display Alive reference count: 0.

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Justin Liu 6 Reputation points
    2022-08-18T03:18:02.167+00:00

    How is this not a bug?

    1 person found this answer helpful.