C + + memory detection function _CrtSetBreakAlloc ()

Source: Internet
Author: User

After you close the C + + program, after the VS compiler's output window

The following conditions occur:

<span style= "FONT-SIZE:18PX;" >f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp (156): {930} normal block at 0x0075e3f8, bytes long.  Data: <   w            > CF DF------------------------928} normal block at 0x0075e328, bytes long. Data: <   wd     u ' u > 98 CF DF-E4-E4 (926} normal block at 0x0075e278, byt Es long. Data: <                > xx, xx, xx, xx, xx (925} normal block at 0x0075ef18, bytes long. Data: < > XX at the xx, xx xx xx                

This situation indicates that your program has a memory leak, relying on these characters we can only know where the wrong address, but where the specific error we can not judge.

Microsoft has provided

Long _CrtSetBreakAlloc (    long Lbreakalloc);
parameters: lbreakalloc The number of assigned orders, you can set breakpoints.

Return value: Returns the placement breakpoint setting the previous object assignment order number.

_CrtSetBreakAlloc   allows applications to detect the origin of specific point memory allocations and trace back requests through interrupt execution memory leaks.   function uses the allocation of the number of objects allocated in the heap when allocating memory blocks.

Example:

BOOL tmapp::initinstance ()
{
 _CrtSetBreakAlloc (928);//928 is the memory address where the leak occurred
 ...

}

This way, when running to the 928 address value program goes into Debug breakpoint mode, we can find the location of the memory leak in the code based on the call Stack.

C + + memory detection function _CrtSetBreakAlloc ()

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.