JetBrains JVM Debugger Memory View plugin
Looking for new tools during my recent R&D activities to improve my development experience and make life with Android Studio easier, I found a useful plugin that I've never heard of. That's why, I decided to write this powerful tool and how it helps me debug my application with memory.
What is the plugin about?
According to the plugin page:
This plugin extends the built-in JVM debugger with the ability to observe objects in the JVM heap during a debug session.
The memory view is grouped by class name to display the total number of objects in the heap .
When you debug the code step by step, the "Diff" column shows the change in the number of objects between the debugger stops (debugger stops, that is, debug points). This way you can easily see how your stepping code affects the heap.
Double-click the class name to open a dialog box containing instances of the class. This dialog allows you to filter instances by computed expressions . All debugger actions (such as checking, marking objects, evaluating expressions, adding to observations, etc.) can be applied to instances in this dialog.
How to install this wonderful plugin?
Open the Android StudioPlugins page:
Press the Install jetBrains plugin… button, search for JVM Debugger Memory View and Install.
Restart Android Studio after installation.
At first glance:
After returning to Android Studio, you will find that the Memory View Tool Window has been added to the right side of the toolbar.
Memory View Tool Window
Memory View Tool Window
If you do not see the memory view, open the tool window and use the main menu: View→Tool Windows→Memory View.
First, this tool will display data only when debug breakpoint is set and run during debug mode.
Second, I'm going to mention that I've read some of the warnings and errors that can happen with Android Studio, but I haven't encountered it.
Warning: Android Studio version contains the following restrictions:
Let's debug!
After running the application in debug mode and pausing on BreakPoint, you will see a magical picture:
What interests us most is the Diff column. When you debug the line of code step by step, you will see how many new object instances will be created or destroyed!
I want to find my own object (i.e. ProfileModel class), so I searched for it:
As you can see that I have updated the ProfileModel vairable in this line of code, before GC deletes the old object I get the difference is +1 and can also access the old object that was not possible before. By double-clicking on this record, I will get an instance of the ProfileModel class in the window:
This window also allows you to filter instances by computed expressions using class methods. For example, you can use the isSuccessful method of the OkHttp Response class to filter responses that are unsuccessful loading in memory:
Instance filter function
Another useful feature is tracking new instances, which you can enable via the right-click menu in the Memory View Tool window:
This feature helps you keep track of the code for new instances of generated classes!
The above is the IDEA memory debugging plug-in introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!