Dosihris
Dosihris

Reputation: 145

UWP Memory leak

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

Upvotes: 1

Views: 1609

Answers (3)

Dosihris
Dosihris

Reputation: 145

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...

Upvotes: 1

Dosihris
Dosihris

Reputation: 145

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.

Upvotes: 3

Nico Zhu
Nico Zhu

Reputation: 32785

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.

Upvotes: 0

Related Questions