Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

MAT, a sharp tool for memory leak analysis

Shulou Source: shulou.com Published: 2022-06-03 03:33:54 10月03日 Update

MAT:Memory Analyzer Tool

Is a fast and powerful java heap analyzer that can analyze and find memory leaks and other problems

Get the dump file stored in the memory snapshot, and you can use it to analyze

Download address: http://www.eclipse.org/mat/downloads.php

Basic concepts:

Shallow Size: the amount of memory occupied by the object itself

Retained Size: the current object size + the object size to which it refers directly / indirectly, the sum of the two

Analyze memory leaks due to code through MAT:

-take a memory snapshot (.hprof file):

Method 1: set it in tomcat/bin/catalina.sh so that heap information is printed when jvm crashes:

-XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=path_address

Method 2: use the commands jps and jmap to get a memory snapshot

Jps-m-l lists the process status information running in JVM (gets the pid of a process for use by subsequent commands)

Jmap-dump:format=b,file=xxx.hprof pid dump process memory usage into a file

Method 3: using jvisualVM

-use MAT tool to analyze:

Create a new folder (because many temporary files will be generated during analysis) and put in the .hprof files to be analyzed

Open MAT and select the .hprof file you want to analyze

During the analysis, follow the tips given by MAT step by step

Note:

Because the memory snapshot is instantaneous, it may need to be captured several times and analyzed many times before the problem can be found.

After the analysis, a compressed package will be generated. If you don't understand it, you can analyze it directly to the developer.

Tags: Parse memory file snapshot size object method time process information command problem power sum item person code analyzer function powerful Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Docker Apple Linux Shulou Tech Info