In the development of Linux products, it is often necessary to pay attention to the system memory usage, and to evaluate the memory usage of a single process, so that we can choose the appropriate machine configuration to deploy our products.Linux itself provides some tools to facilitate the implementation of these requirements, to see the process real-time resou
One of the most troublesome problems in C/C ++ development is memory management. Sometimes it takes several days to find a memory leak or a memory access out of bounds, if there is a tool that can help us do this, valgrind is such a tool.
Valgrind is a software suite based on a simulated program debugger and analyzer
The reason to write this blog is because you are writing a Nginx disk cache management program, has now entered the testing phase, the test on this program is divided into several major steps: 1. Memory management is correct (because this program itself open up a lot of memory space for cache management, At the same time, the program itself is based on C/s + + development,
the requested space is released (Memory leaks–where pointers to malloc ' d blocks are lost)
Malloc/free/new/delete application and free memory matching (mismatched use of malloc/new/new [] vs Free/delete/delete [])
Overlap between src and DST (overlapping SRC and DST pointers in memcpy () and related functions)
Repeat free
Overview of the use of Valgrind under Linux
1. Development background:
When programming with VC in Windows, we usually need to run the program in debug mode, and the debugger will print out memory information that is allocated on the heap while the program is running, including the code filename, line number, and memory size, when exiting the program. This feature is a built-in mechanism provided by the MFC Framework, encapsulated within its class s
= = by0x100008f26: Lept_set_string (LEPTJSON.C:207)==22174= = by0x1000083fe: Test_access_boolean (test.c:187)==22174= = by0x100001839: Test_parse (test.c:229)==22174= = by0x100001793: Main (test.c:235)==22174==It finds that Lept_free () relies on an uninitialized value to jump, which is v.type, and the error is along the self-test_access_boolean ().When writing unit tests, you should consider which order of execution will have a chance of error, such as memo
of the phone's memory leak, just a practical Linux small command: mtrace (memory trace), which can be used to assist in locating the leak. Development, should have heard more or less mtrace.Below, let's take a look at the program:#include Some friends have to say, a glance
In Linux under some C language programs, the biggest problem is that there is no good programming IDE, of course, like KDevelop and other tools are quite powerful, but I still used to use the KDevelop tool, because there is not a custom programming IDE, Memory detection is also a big problem with programming programs in Linux
location of the phone memory leak, just a useful linux little command: mtrace (memory trace), which can be used to assist in locating the leak. Development, should have heard more or less mtrace.Below, let's take a look at the program:[CPP]View PlainCopy
#include
also use a global variable to write down the number of applications, releases). In order to observe which block had been applied, but did not find the corresponding release place.In Summary, there is no easy way to resolve memory leaks. The prevention method is to standardize their own code writing, to do a good job of the application and release. Remember to release the memory you requested before you ret
ignoreobject () to re-enable liveness-checking in an Object-by-object basis.) "Normal" mode, as the name implies, is the one used most often at Google. It ' s appropriate for everyday heap-checking use.In addition, there is and other possible modes:
as-is
local
as-is is the most flexible mode; It allows specify the various knobs of the heap checker explicitly. local activates the explicit Heap-check instrumentation, but does no turn on any whole-progra M
local JprofilerNext: NextNext:Next:Select the server-side JDK version:Java-version ViewNext:Destination server IPNext:Server Jprofiler installation directory, default is opt directorySelect WebLogic Startup scriptUpload the generated startweblogic_jprofiler.sh to the WebLogic startup directoryPrompt after restarting WebLogic connectionThe link Success page shows as follows:Third, actual combatA: Mission ObjectivesFind out why memory is growing in you
In a previous blog post Linux kernel module, a way to find out about memory leaks >> , I introduced a method of finding kernel memory leaks. This is a few months, and customers complain: using the product 5 days or so, the SUSE server due to memory exhaustion and crash. O my God, don't, run on my machine good WOW (pro
1. Kernel Add memory leak feature option kernel memory leak detector kernel debugging memory leak debugging Compile kernel With debug info go through make menuconfig into the configuration options interface to enter kernel hacking
1.ValgrindIntroduction1. One of the most common mistakes when we write C + + is memory leaks, which are inextricably linked to programmers ' programming habits. If you are applying for memory space, you can immediately release the memory in the appropriate location. The case of a memory
given below#include void mtrace (void)void Muntrace (void) Usage examples:#include #include int main (char *argv[]) { #ifdef DEBUG mtrace (); #endif int *a =malloc (sizeof (int//0;} In the above code, we did not call Muntrace (), nor is it recommended. The reason is that in Linux C not only are your programs tracking dynamic memory issues, C libraries are also used. If you call
.... ..... ....... ..............................Snapshot resolved.Started HTTP server on port 7000Server is ready.
Dump file created Thu Mar 16:45:06 CST 2015
Snapshot Read, resolving ...
Resolving 264282 objects ...
Chasing references, expect, dots ..... ..... ..... ....... .........................
Eliminating duplicate references .... ..... ....... ..............................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.
3. The address bar input ip
leakage occurs. If it is released more, problems may occur. In the above program, the pointer p and pt point to the same memory, but are released twice. The system will maintain a dynamic memory linked list on the stack. If it is released, it means that the block of memory can continue to be allocated to other parts. If the
int(5);DeleteP1; Print_leaked_memory ();return 0;}Compile command:g++-o test test.-g-Wl,---Wl,--wrap,freeRun:"==="-d"["-f-d"]"-e testMethod Analysis:Advantages:(1) At the end of the program run, the print program memory leaks and the code that causes the leak occurs the file and line number(2) C + + is applicable(3) Need to modify the product source code to achieve the function(4) all. O and static librari
1. ccmalloc-for C and C ++ in Linux and SolarisProgramThe simple use of Memory leakage and malloc debugging library.
2. dmalloc-Debug malloc library.
3. electric fence-malloc () debugging library written by Bruce perens in the Linux distribution.
4. leaky-programs for detecting memory leaks in
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.