"C language" a record of a memory leak analysis

Source: Internet
Author: User

Running a program today, the program just started with a small amount of memory, during the run, found that the memory used will always increase.

Viewing the discovery in a CAT/PROC/PID/STATM way is really growing.

And after the program is ported to another platform, it will not run directly.

——————————————————————————————————————————

I don't understand why, thinking where the memory leaks, but it's almost impossible, because all of my memory allocations are done during initialization,

Some pool and queue are allocated, and no memory is allocated at all while (1) cycle.

I then checked with the Valgrind tool, and of course I had a lot of memory allocations without free, but it didn't matter to me because I

The while (1) does not continue with malloc.

——————————————————————————————————————————

But heck, the whole operation is going to grow.

What the hell is going on here? What's going on here?

It turns out that after malloc, the allocated memory will not be allocated until it is actually used, and on the embedded platform it seems to be allocated well in advance.

The features of malloc I certainly know that this time I did not notice because I think I allocate memory is much smaller than the memory of the machine, even if all occupied, will not always increase,

And the reality is, I allocated the memory is really too large, more than the machine's memory, when more than, the direct error, this time my intuition of the reaction is where leaked, and did not want to malloc problem.

Because I wrote a new library, I thought it was a problem with the new library.

"C language" a record of a memory leak analysis

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.