Mohsen Mirhoseini

@mohsenoid

A useful memory debugger plugin for Android Studio

January 14th 2017

JetBrains JVM Debugger Memory View plugin

JetBrains JVM Debugger Memory View plugin

During my recent R&D activities looking for new tools to improve my development experience and making life easier with Android Studio, I found a useful plugin which I have never heard before. This is why I decided to write about this mighty tool and how it helps me with memory debugging my applications.

What is the plugin about?

According to plugin page:

This plugin extends the built-in JVM debugger with capabilities to explore objects in the JVM heap during a debug session.
The Memory View shows you the total number of objects in the heap grouped by their class name.
When you’re stepping over the code, the Diff column shows how the number of objects changes between debugger stops. This way you can easily see how the code you’re stepping over affects the heap.
A double click on a class name opens a dialog with instances of this class. The dialog lets you filter instances by an evaluated expression. All debugger operations such as Inspect, Mark Object, Evaluate Expression, Add to Watches, etc can be applied to instances in this dialog.

Since all the BOLD sentences are really interesting, I understand if you want to go and download this plugin to have your own experiences instead of reading more here…

How to install this wonderful plugin?

Open Android Studio Plugins page:

  • Shortcut: press command/ctrl+shift+A , type Plugins and press enter
  • or open Preferences/Settings: (Mac: Android Studio -> Preferences / Windows & Linux: File -> Settings) and find Plugins page:

press Install JetBrains plugin… button and search for JVM Debugger Memory View and Install.

then you have to restart the Android Studio.

At first glance:

After getting back to Android Studio you will find Memory View Tool Window added to right side of the toolbar.

Memory View Tool Window
If you do not see the Memory View, to open the tool window, use the main menu: ViewTool WindowsMemory View.

First of all, this tool only works and show data while the app is running in debug mode and you have paused the run using a BreakPoint.

Secondly, I have to mention that, I read about some warnings and bugs that might happen with Android Studio, which I didn’t face during my experience.

WARNING: version for Android Studio contains few restrictions:
- Getting a large number of instances may fail and stop VM due to Android memory limitations.
- Android Studio may freeze, see this bug

Let’s debug!

After running you app in debug mode and pausing on a BreakPoint you will see the magic happens:

One of the most interesting points about this table is the Diff column while stepping through your code lines you will see how many new instances of objects have been created or destroyed!

I want to look for my own object (i.e ProfileModel class), so I search for it:

As you can see I have updated the ProfileModel variable in this line of code and I get the Diff +1 before GC remove the old one and also can access the old one which was not possible before. By double clicking on this record I will get instances of the ProfileModel class inside a window:

This window also allows you to filter instances by an evaluated expression using the class methods, for instance, you can use isSuccessful method of OkHttp Response class to filter unsuccessful responses loaded in memory:

Instances filter feature

Another useful feature is Tracking new instances, which you can enable by the right click menu inside Memory View Tool Window:

This feature helps you with tracking codes which have been generated the new instance of the class!

You can read more about this plugin inside JetBrains blog, and also let them know about new features that might come to your mind or bugs if you find some.

TL;DR:

This article was about a JetBrains plugin which might help you in memory debugging your applications with Android Studio and access to all loaded objects during an application run.

Thanks for reading this article. Please leave a comment and share with us your experience with this plugin and how you find it useful during your own tests.

I found this plugin useful so I decided to share it with you, recommend this to your friends if you think it is useful and let them enjoy, too.

You can also and follow me for more articles Mohsen Mirhoseini Argi.

Hacker Noon is how hackers start their afternoons. We’re a part of the @AMI family. We are now accepting submissions and happy to discuss advertising & sponsorship opportunities.
If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, don’t take the realities of the world for granted!

More by Mohsen Mirhoseini

More Related Stories