Memory leakage detection method

Source: Internet
Author: User

1. Add in the header

1.1 Method 1:

# Ifdef _ debug <br/> # define debug_malloc (s) _ malloc_dbg (S, _ normal_block, _ file __, _ line __) <br/> # define malloc (s) debug_malloc (s) <br/> # include <crtdbg. h> <br/> # define debug_new new (_ normal_block, _ file __, _ line __) <br/> # define new debug_new <br/> # endif <br/> // _ file path <br/> // _ line _ row number

 

1.2 Method 2:

# Ifdef _ debug <br/>/* <br/> _ crtdbg_map_alloc must be included in # include <crtdbg. h> previously defined <br/> but defining _ crtdbg_map_alloc in the Code does not work. The following definition is required: <br/> // # define debug_malloc (s) _ malloc_dbg (S, _ normal_block, _ file __, _ line _) <br/> // # define malloc (s) debug_malloc (s) <br/> therefore, it is best to define _ crtdbg_map_alloc directly in Preprocessor. <Br/> */<br/> // # DEFINE _ crtdbg_map_alloc <br/> # include <crtdbg. h> <br/> # define debug_new (_ normal_block, _ file __, _ line _) <br/> # define new debug_new <br/> # endif

 

2. Add

_ Crtsetdbgflag (_ crtdbg_alloc_mem_df | _ crtdbg_leak_check_df); <br/> _ crtsetbreakalloc (91 ); <br/> // _ crtsetdbgflag is added, and the memory leakage detection is performed. <br/> // _ crtsetbreakalloc is added to this sentence, and the breakpoint is broken to 91 lines at the leak location, the program is no longer running. Without this sentence, the program runs and the output file line number is equal to the leaked information. <Br/>

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.