1

i have a problem with UWP. I think there is a big memory leak problem in the views. The memory of the views it not released anymore. You can realize this on every navigation. The praid solution for the navigation problem is the navigation cache, ok, but i have a listview with a very complex itemtemplate. Every time an item is inserted in the listview, a new item template view is created, and never released anymore. i wrote a small example.MemoryLeakExample Click on the button inserts 20 items. The app starts with 24MB of Memory. After 5 clicks we are at 100MB. Why?

Can anybody help me and tell me, what i'm doing wrong?

Greetings, Nico

Dosihris
  • 145
  • 9
  • 1
    have you taken a look at my examle, chip? It fits all your requirements! – Dosihris Jul 06 '18 at 07:06
  • Possible duplicate of [Do all UWP apps leak memory when navigating pages?](https://stackoverflow.com/questions/49831807/do-all-uwp-apps-leak-memory-when-navigating-pages) – ClaudiuC_MSFT Sep 25 '19 at 09:14

3 Answers3

3

If somebody is interested in this. The answer is: there is no answer.

I submitted a bug to Microsoft with this, and after three month of writing samples for Microsoft, show and explain them the bug, talking to Microsoft people and doing a lot of other time wasting stuff with them, they filed a bug on this and provided a sample to the product team.

So, the memory leak is real and my Code is not just a bad code.

Dosihris
  • 145
  • 9
1

Microsoft told me this week that they have fixed the bug! It was a handle leak. They put it into the windows inside preview build and the fix will be shipped with the spring update to windows. So hopefully this is the real and last answer to this leak...

Dosihris
  • 145
  • 9
0

You could diagnose this with Memory Usage Tool in Visual Studio. For detail steps, you could refer Diagnosing memory issues with the new Memory Usage Tool in Visual Studio. And you could take snapshot in order to capture the state of the application memory. For more detail you could refer this case reply.

And I have also checked your code. I found you used Page as DataTemplate. And that is no good idea. Because, you will create more page instance when added the item to list view. And UI virtualization will does not work. I verified it with Memory Usage Tool. Please check the following screen shot.

enter image description here

The count of TestBlockView increased by 11 and consume more memory.

And I have tried place all the TestBlockView xaml into the DataTemplate. No matter how many items I add, the memory will remain within reasonable limits.

For your requirement, you could make DataTemplate directly rather than using Page. And you could also use UserControl to replace Page.

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
  • Thanks for the answer, but unfortunately inheriting from UserControl does not release the memory, and copy the entire Template directly into the view is a very bad solution, because i want to reuse the template. Do you have an idea from which class i can inherit my template without loosing all the memory? – Dosihris Jul 06 '18 at 20:10
  • In general, we often place this massive code in the UserControl or separate Datatemplate. And I tested the latter one it works. – Nico Zhu Jul 09 '18 at 01:51