Memory Leak analysis tool Tmemmonitor (TMM) Usage Introduction

Source: Internet
Author: User

because of its flexibility and high efficiency, C + + has always been one of the mainstream programming languages, but the allocation and release of its memory is managed by the programmer itself, which causes a memory leak when the program fails to release memory that is no longer used due to negligence or error. In large, complex applications, memory leaks are often the most common problem, so it is necessary to resolve memory leaks in a timely manner. Tmemmonitor (TMM), as a professional, accurate, and easy-to-use memory leak analysis tool, can help C + + programmers quickly solve the headache of memory leaks.

tmm:http://download.csdn.net/download/tmemmonitor/9135585

 

A Background

currently on the market there are some memory leak dynamic detection tools under Windows platform, such as Umdh,vld,purify,boundscheck, where Purify and Boundscheck are expensive commercial software, UMDH need to manually capture memory snapshots, Operation Threshold is high, VLD need to modify the source code, and these tools are false alarm, so the accuracy is not high. For the Windows platform, C + + programmers urgently need a professional, accurate and easy-to-use memory leak analysis tool.

Two TMM Introduction

The TMM is a run-time C + + memory leak Detection tool. TMM that when the process exits, the heap memory is not freed and no pointers point to a non-primary memory block that is a memory leak, and in turn introduces a garbage collection (GC, garbage Collection) mechanism that detects all the non-referenced memory cells in the heap memory when the process exits. Thus the memory leak detection accuracy rate is 100%.

The TMM tool consists of two parts, the first part is the client's detection interface, and the client part is primarily responsible for monitoring the memory behavior in the target process and calculating the memory leaks. As soon as the detected program is added to the monitoring list, and then the program is run properly, the following is the client interface:

the other part is the presentation and analysis of the results. TMM supports both local and online query methods. When viewed locally, provides the ability to sort results by leak or leak size, and gives detailed analysis reports in the Data folder of the installation directory. Users can also use QQ account login Wetest website on the memory leak situation online query. The following is a local view of the results:

Three Features and benefits of TMM

Professional

Ø the fastest injection technology

Accurate GC-based algorithm with no memory snapshots

Ø Lossless Target Program performance

Ø accurate positioning of the test results to the code stack information

Accurate

Ø two traversal of pointers in heap memory objects

Ø Register-level problem tracking, complete scanning of pointers in 32-bit registers per line thread

Ø do not miss the contents of the Global data area

Use

Ø Support for custom programs

Ø no need to compile, immediately use

Ø one-touch operation without switching

Four Algorithm principle

1. Algorithm for replacing/injecting heap memory allocation function

There are several levels of memory allocation functions in Windows, where the bottom line is the RTL series functions provided by Ntdll.dll, on top of which are the heap management functions provided by the Windows API, and the Malloc/free functions and new/are provided by the C/S library. Delete operator, it is difficult to replace such a complex function, and if you replace the existing heap allocation function, you cannot do exactly the same as the original function, so replacing the native heap allocation function is almost not feasible for Windows systems. Then only wrap (wrap) These heap allocation functions.

The memory detection tools under Linux, such as Valgrind, take the method of parcel heap allocation function, but the method of wrapping it is opaque and extra frame is added in the call stack. The TMM uses a fully transparent wrapping function, which divides the hook function into the front and back two parts (1). Execute the Per-hook function before the function call, and call the Execute Post-hook function before the function returns. With the front and back hook functions, TMM can get parameters before the heap allocation/deallocation function executes and modify parameters such as allocation size, and after the function executes, records the size and address of the allocation, and information such as the call stack.

Figure 1

2. Algorithms for leak detection

TMM uses memory leak detection based on heap memory accessibility (reachability-based leak detection), the core of which is to detect (scan) no pointer-pointing heap memory, specifically divided into five steps:

Step 1. When the process exits, suspend all threads to prevent the data from changing during the scan. Assume that the heap memory layout in the process is now shown in 2;

Figure 2

Step 2. Statistical Root-set, which consists of the registers of each thread, all non-heap memory, all the data areas of the Cheng top RSP/ESP and all the libraries;

Step 3. From Root-set to traverse Figure 2, labeled with pointers to the memory block, that is beginning reachable blocks,3 A, C;

Figure 3

Step 4. Since beginning reachable blocks also contains pointers, it is possible to traverse beginning reachable blocks to find the memory block that its internal pointer points to and tag, 4 B;

Figure 4

Step 5. The memory leak is statistically detected, which is the heap memory block D, E, F unreachable in Figure 4.

Five Use steps

Figure 5

1. Start TMM with administrator permissions.

2. In the Monitoring list right-click Add target program, normal operation.

3. Exit the target program normally.

4. Wait patiently for the test result to be generated (when the target program state is changed from running to NULL, the program exits normally and the test results are generated).

5. View the results.

Six. Precautions

1. When installing TMM, the user should have administrator permissions, and TMM does not support the Chinese installation path.

2. You need to modify the registry when using TMM, in case of security software pop-up warning, you can use TMM to join the trust list.

3. The instrumented program cannot be a shell version because the function name and function address of the shell program have been confused.

4. The tested program needs to be release version.

5. If you want to display the detailed stack information of the leak point in the analysis report, place the same version of the PDB file in the instrumented program sibling directory, and the directory does not support Chinese when the PDB resolves.

6. The use of TMM causes the program to exit time-varying slow is a normal situation, when TMM is in the process of statistical memory leaks, do not manually force the end of processes.

Seven Summarize

the TMM is suitable for memory leak analysis of all PC-C + + programs. For the program under test, do not need to modify the source code, run a test program will be able to accurately locate the leaked file name and line number. TMM is a professional, accurate and easy-to-use memory leak detection tool that is worth every programmer's own.

tmm:http://download.csdn.net/download/tmemmonitor/9135585

QQ Support: 2304186838

Contact email: [Email protected]

Memory Leak analysis tool Tmemmonitor (TMM) Usage Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.