JustTrace now seamlessly integrates into Visual Studio to provide an unobtrusive development experience, but that’s not all we did for the Q1 2013 release. We also enhanced memory snapshots to provide more data to discover the cause of a memory leak.
I created a simple web application to show tweets, and it appears that memory consumption creeps up while it’s in operation. To find out why this is happening, I select the Memory Profiler button in the Visual Studio toolbar before running the application.
The application starts as it normally does; JustTrace doesn’t interfere with my workflow. I then type my Twitter handle and get tweets.
At this point, it’s crucial to get a snapshot for comparison. To do this, I go to the JustTrace Session tab in Visual Studio (open it from the JustTrace menu if it’s closed) and click Get Snapshot.
I want to repeat the actions I’m analyzing for the memory leak, so I return to the page and Get Tweets for another person. I then use the Kill & Get button in the JustTrace Session tab to get my final snapshot to compare to the previous. For more information on these selections, read the article or watch the video for Using the JustTrace Timeline.
Since I’m comparing instances at two points in time, JustTrace takes me to the Type List Diff view. On this page, I can see whether the instance count and size grew or shrunk for each type. It turns out my suspicions of a leak were right, as calling the Get Tweets action twice doubled the count for Twitter.Tweet.
JustTrace will navigate to one of our new features when double-clicking the type or using the Instances button in the ribbon.
The Instances Diff view provides granular detail for each instance of the type such as the size, retained size, age (garbage collection generation), and status. I want to know why the previous instances survived, and this requires more detail. Obtain this by double-clicking a surviving instance or by pressing the Root Paths button.
The Root Paths view is familiar, but we’ve added static field names. As it turns out, this information is necessary in this example, since the instance I chose earlier survived garbage collection due to a static dictionary. There could be a cache and release mechanism in place to prevent repeated requests to a remote server, but it’s definitely something I want to review in case it’s simply retaining all instances. Thanks to JustTrace, I now know where to look!
When a performing a certain action in my application, memory increased. Since it continued to increase each time I called the action, I suspected a memory leak. Using JustTrace, I was able to determine that the garbage collector was not collecting instances created during the action as a static field referenced a dictionary containing these instances.
Happy profiling, and let us know what you think of JustTrace in our Feedback Portal!
Chris Eargle is a Microsoft C# MVP with over a decade of experience designing and developing enterprise applications, and he runs the local .NET User Group: the Columbia Enterprise Developers Guild. He is a frequent guest of conferences and community events promoting best practices and new technologies. Chris is a native Carolinian; his family settled the Dutch Form region of South Carolina in 1752. He currently resides in Columbia with his wife, Binyue, his dog, Laika, and his three cats: Meeko, Tigger, and Sookie. Amazingly, they all get along... except for Meeko, who is by no means meek.
Copyright © 2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.