1

I have developed one UWP application.In that nearly 20 windows are there.

Every window contains lot of Xaml controls. For some time it's working fine.

But after usage of some time application is getting very slow.

After doing some R&D I came to know that it's called Memory Leakage.

As per my knowledge in .Net Garbage Collector has to take care of this if I am not wrong.It seems like In UWP Application it is not happening. So I thought I should use GC.Collect() in Page Unload Event.

Is that correct approach or anything else I need to do to release memory which are used by the window controls?

Anil
  • 3,722
  • 2
  • 24
  • 49
Sagar
  • 371
  • 9
  • 26

2 Answers2

2

The performance optimization is a vast subject and may not be possible to answer on an open ended question (without knowledge of your environment and architecture etc).

However you can use the Visual Studio profiler to measure and track performance and to find out the area where you need to take action, these can be;

  • Data binding
  • UI Virtualization
  • Image rendering
  • Visual Tree Size

Further reading these urls may also help you.

ms docs and this blog

Anil
  • 3,722
  • 2
  • 24
  • 49
  • Thanks for your suggestions. Could you please clarify me once that is it cause any issue if I use GC.Collect() method in Unload event. Does GC.Collect() releases the memory which are used by the current page. – Sagar Apr 04 '17 at 09:28
  • Refer http://stackoverflow.com/questions/4257372/how-to-force-garbage-collector-to-run and https://forum.unity3d.com/threads/uwp-resources-unloadunusedassets-behaves-differently-against-weakreference.416888/ and https://github.com/Windows-XAML/Template10/issues/777 and https://microsoft.github.io/Win2D/html/RefCycles.htm – Anil Apr 04 '17 at 09:42
1

The GC takes care of orphaned objects or objects that are no longer referenced by any other classes. when the GC finds objects like these it removes them from memory. memory leaks happen when an object is referenced by another class even after it is done with it. this means you need to look at your code and find where this is happening. you need to help GC in doing its job by making sure you no longer reference objects you don't need.
I also wouldn't recommend using GC.Collect in page unload event since GC has to freeze threads in order to collect. this might impact performance.

MrCSharp
  • 1,143
  • 17
  • 28