malloc kills memory in invisible

Source: Internet
Author: User

The malloc function in C is allocated memory, and the variables of the inner life of the function allocate memory, but when the function is released, the memory is freed so that it does not consume memory, but the malloc function is different.

As follows

typedef struct NODE

{

int A;

Node* Next;

}lnode,*llist;

Llist a= (llist) malloc (sizeof (Lnode));

This line is the code that allocates memory, if this function is called in a function, the memory allocated by the function will persist unless it is released.

Free (a);

This line of code is the code that frees the memory,

There is no relation to releasing the memory in turn, but if the function is called more than once, it is very prone to problems.

For example, I wrote a chess program, which only allocates the memory of the structure of the above example size, and does not release

That code ran hundreds of millions of times, every time my program was in memory, and then I found out what the reason was.

So the memory that you allocate, the tears you have to release it.

malloc kills memory in invisible

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.