In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
C++ memory leak troubleshooting methods, in view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple way.
First, experience investigation
Experienced programmers will track where memory is requested in the program, such as the malloc or new keyword. In one case, we apply and release according to the program logic, and we should prevent memory leaks in case the program does not free memory as expected when an exception occurs.
II. Introduction to the use of Visual Leak Detector for Visual Clipper 2.1 Visual Leak Detector for Visual C++
Visual C++ provides built-in memory leak detection, but its functionality is minimal at best. This memory leak detector was created as a free alternative to the built-in memory leak detector provided by Visual C++. Here are some of the features of Visual Leak Detector that are not present in the built-in detector:
Provides a complete stack trace for each leak block, including available source file and line number information.
Detect most, if not all, types of in-process memory leaks, including COM-based leaks and pure Win32 heap-based leaks.
Selected modules (DLL or even the main EXE) can be excluded from leak detection.
Provides a complete data dump of the leaky block (in hexadecimal and ASCII format).
Customizable memory leak reports: can be saved to a file or sent to the debugger and can contain variable levels of detail.
Other after-sales leak detectors for Visual C++ are already available. But most of the really popular ones, such as Purify and BoundsChecker, are very expensive. There are some free alternatives, but they are often too intrusive, restrictive or unreliable. Visual Leak Detector, the only free Visual C++ memory leak detector currently available, neatly packages all of the above professional-level features in an easy-to-use library.
2.2 Visual Leak Detector source code acquisition compiling 2.2.1 source code acquisition, related git address git clone https://github.com/oneiric/vld2.2.2 release version acquisition
There is Visual Leak Detector for Visual C++ Releases on the git home page, just download the corresponding version and install it.
2.2.3 compile
The vs version required by this code is 2019, and the version used by the blogger is 2015. An error will be reported at compile time.
Project-- > Properties-- > General-- > platform tool set-- > Select Visual Studio 2015 (v140) to confirm that OK2.2.4 comes with gtest engineering testing.
Compile the vld_main that comes with the project for testing, and the gtest project in the project tests the relevant memory leak scenarios.
2.3 how to test your own project 2.3.1 configure the project
Introduce the vld.h file into your project and configure the vld.lib library in the link library
Set the current project to Debug mode to display stack-related call information
2.3.2 write simple test cases
Three.h
# pragma once class three {public: three (); ~ three ();}
Three.cpp
# include "three.h" three::three () {} three::~three () {}
Main.cpp
# include # include "three.h" using namespace std; int main () {cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.