Jaa


Troubleshooting Memory Leaks in Windows Store Apps

 

There are many options to troubleshoot memory leak issues in .NET applications. Most common approach is capturing a memory dump just before terminating the process and looking at the object count and gcroots. Most of the time this approach works, but in few cases where the application has too many short lived and too many long lived objects, it is hard to determine which objects are leaking and which objects are cached.

Another common approach is capturing multiple snapshots at the same location of the application after executing the application functionality that causes memory leaks.  Comparing these snapshots, we can easy tell which object count is increasing and we can do gcroots on only those objects.

In this blog post, I would like to show how NP .NET Profiler can collect multiple snapshots and generate different reports to determine which object count is increasing.

Steps to capture profiler traces

 

  1. Download NP .NET Profiler tool from here

  2. Extract the NPStoreApp.zip file to c:\temp\np folder

  3. Double click on the NPStoreApp.exe

  4. Select the Windows Store Application from the listbox

  5. Set the “Profiler Type” to “Memory Profiler”

  6. Set the “Filter Type” to “Capture Object Count Snapshots”

    profilersettings

  7. Now, click on the “Start Profiling” button

    • This will launch the application and the profiler will be monitoring the app for object allocations
    • The profiler log files are saved to the temp directory
    • Click on the “Open Output Folder” to view the log files
  8. Reproduce the memory leak issue (here in the test app, click on the memory test button)

  9. After the first iteration, capture a snapshot by clicking on the “Capture Memory Snapshot” as shown below

    capturesnapshot

  10. The snapshot count increases as shown below

    count_1

  11. Repeat the same steps to reproduce the leak few more times and click on the “Capture Memory Snapshot” button after each iterations

  12. Now click on the “Capture Memory Dump” to collect a full memory dump of the process

  13. Now click on the “Stop Profiling” button

  14. Close the application

  15. Click on the “Show Reports”, this will launch NP.EXE and generates different reports

  16. The default report is “Compare object count with snapshot # 1“, here is the report. From this report it is clear that System.Exception objects are getting created in each iteration and are not getting released

    Click the image for a larger view

    compare_snapshots

Comments

  • Anonymous
    November 22, 2013
    The comment has been removed