Use Delphi fastmm4 (1)

Source: Internet
Author: User

Memory leaks often occur locally.Code, Especially in the case of multithreading and exceptions, fastmm4 is particularly useful in the Delphi environment.

The debugging process is as follows:

1. Enable the fastmm4 debugging function. First, put fastmm4 at the beginning of your project. For example:

Fastmm4,
Main in 'main. pa' {mainform },
You can define the compile constant fulldebugmode in the project. Copy fastmm_fulldebugmode.dll to the executable generated after compilation.ProgramDirectory.

Enablememoryleakreporting. In general, it is enabled by default.

In this way, the full debugging mode is enabled. If memory leakage occurs, a report file is generated. If the IDE runs, a dialog box is displayed. The report file is similar to kicoy_memorymanager_eventlog.txt.

2. The report file consists of two parts, each of which is appended. Therefore, try to clear the report file when running.

The first part is the detailed information of the leakage, and the detailed information of each unreleased memory block is displayed. Example:

A memory block has been leaked. The size is: 28 {A 28-byte memory block is not released after the program ends}

{The call stack when the memory block is allocated, that is, the call stack, can clearly show the order of calling functions. If it is a system DLL, there is a corresponding function name .}
Stack trace of when this block was allocated (return addresses ):

4028e7
4030ec
406649
412365
41236e
411dd3
2017b45
427236
42888c
{This memory type. If it is a string or an object inherited by tobject, a name is displayed .}
The block is currently used for an object of Class: Unknown

{Display the memory block with 256 characters as the content prompt .}
Current memory dump of 256 bytes starting at pointer address limit bdd8:

The second part is summative content, for example:

{This small memory block leakage report, if there is a large memory block leakage, will add a line specifically prompting large memory block leakage .}
This application has leaked memory. The small block leaks are (excluding expected leaks registered by Pointer ):

{Memory block leakage of 1-28 bytes, unknown type}
21-28 Bytes: Unknown X 1

Note: Memory Leak detail is logged to a text file in the same folder as this application. To disable this memory leak check, undefine "enablememoryleakreporting ".

With this report, I only learned about the memory leakage, but further investigation is required if no memory is released.

The survey targets:

1. The code in the function in which the memory block is allocated.

This can be viewed in the report based on the content and call stack. The first 256 bytes can be analyzed. If we speculate that the Allocator calls the stack, it directly points out the allocation function, but it is only some addresses and cannot directly know the function name and code segment. In this case, you need to view the binary memory image in the Delphi IDE environment, that is, the view CPU function.

After the breakpoint is set and stopped, you can view the CPU. In the menu view => debug window => CPU shortcut: CTRL + ALT + c

View CPU window:

In the center is the memory image, and the source code is also marked accordingly. The address in the left column is the address in the call stack in the memory report. You can find the corresponding code on the page to know where to allocate the memory.

2. check whether the memory to be released is called. You can use logs or breakpoints for debugging. If the memory is not released, add the code, if a breakpoint does not work, check whether the execution conditions are correct. If the breakpoint does not work, it is likely that the Code will never be executed (dead code ).

In addition:

1. Memory Management does not enable GC to automatically recycle memory, but checks for leakage.

2. Windows system memory leakage cannot be checked, but it is limited to internal applications. However, it is impossible to check for system leakage and only wait for updates.

3. After checking for leaks, check the code to complete the memory release. The report cannot do this.

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.