Use Mallocdebug to isolate and resolve memory leaks in Aix V5.3-useful tools for accomplishing trivial tasks

Source: Internet
Author: User

The malloc subsystem monitoring tool Mallocdebug, included with Aix®version 5.3, can help you isolate memory leaks. Memory leaks are a tricky problem and are costly to handle, so it is important to use good tools to identify and understand the cause of the leak. The sample code provided in this article will show you a way to handle memory leaks.

Introduction

It is necessary to perform dynamic memory allocation when writing an application. It can help allocate the required memory while the program is running, rather than allocating it when the process is started. However, it is also important to manage these memory effectively. Memory leaks are a common problem in large, complex applications. A memory leak occurs when a previously allocated piece of memory is no longer needed or inaccessible, but does not release it, thus resulting in a decrease in total available memory for the process. Although good programming practices ensure the fewest leaks, it is possible to experience memory leaks when using a large number of functions to process the same block of memory. This is especially true when encountering the wrong path.

This paper introduces a memory leak processing method, and discusses how to utilize the Mallocdebug tools included in aix®.

Why memory leaks are hard to fix

An application can release a piece of memory at different times in its lifecycle, depending on the specific situation it encounters. Programmers need to design the application reasonably so that it can know when to release a piece of memory and do it right away, rather than wait longer. Depending on the control process, the release of memory can be done in different parts of the code. It is important to have all the control processes involved, not just the most frequently executed code flow path.

At the same time, releasing the memory before it is ready for release can cause catastrophic errors. Therefore, to understand where the memory blocks are ready to release, you must have a thorough understanding of the control processes in your application.

Detecting memory leaks

A leak may occur when the following symptoms occur:

The errno returned by malloc is set to Enomem.

A core dump occurs, and a function in the stack comes from the malloc subsystem.

When you make a core dump, the process is larger than it would normally run.

The process size, which can be viewed using the PS command, has grown dramatically.

If there are some memory leak symptoms, it is best to use the memory Monitoring tool for analysis. There are many third-party tools, such as Zerofault and IBM rational®purify®, but this article will discuss the Mallocdebug tools that are included with AIX.

Using Mallocdebug to report memory leaks

Mallocdebug is a very easy to use malloc subsystem monitoring tool. By using two environment variables Mallocdebug and Malloctype, you can easily enable the malloc subsystem debugging task for a particular application. You need to export these variables to the Shell that is running the application. In AIX Version 5.3, error Reporting is written to stderr.

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.