Identifying memory leaks

There are various tools like JetBrains dotMemory, PerfView, and others to analyse or identity memory leaks for performance. dotMemory is a very good tool but requires a license for commercial use. In this section, we will use Perf View and see how memory leaks can be identified.

To install PerfView, you can go to Microsoft download centre site, https://www.microsoft.com/en-us/download/details.aspx?id=28567, and download.

It's a simple .exe file and you don't need to install it. PerfView is highly suitable for production use. It is quite easy to use and takes snapshots while your application is running without affecting or freezing the application performance.

Another important tool is the VMMap, which shows complete information, such as size, committed, private, and other information related to storage for a particular process. After running VMMap you can select the process for which you want to know the GC Roots storage information as follows:

This tool is good to get the glance view storage allocation, but to rectify the exact area where the problem persists we will use PerfView.

To take a snapshot from PerfView, run the PerfView and click on Memory > Take Head Snapshot option:

Max. Dump K Objs is the total size of the objects snapshot will be taken. If the size is big, PerView automatiaclly performs Heap Sampling and extracts the maximum of 250 K.

Force GC is an option from where we can explicity run GC to perform garbage collection.

Dump GC Heap takes the snapshot and stores it your PerfView for further analysis. You can take multiple snapshots and compare the differences:

You can open a dump file,  and it opens up the GC Heap viewer that provides a list of aggregate stacks encountered during sampling. It includes the methods frames that were captured during sampling:

The important columns to note are Exc%, Exc, Inc%, and Inc. Exclusive represents the time spent on a particular method, whereas Inclusive represents the exclusive time plus the time x in the methods. We can also drill down each object and see the child objects in the tree.

This is a great tool to identify memory leaks, and to learn more you can refer to the Channel 9 video at the following link:
 https://channel9.msdn.com/Series/PerfView-Tutorial.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.202.177