Basic Malloc/Free

前端 未结 5 503
谎友^
谎友^ 2021-01-20 18:50

If I have a snippit of my program like this:

struct Node *node;
while(...){
    node = malloc(100);
    //do stuff with node
}

This means t

5条回答
  •  北恋
    北恋 (楼主)
    2021-01-20 19:20

    then how do I free up all the memory that I have made with all the loops if I only have a pointer left pointing to the last malloc that happened?

    You can't. You just created a giant memory leak.

    You have to keep track of every chunk of memory you malloc() and free() it when you're done using it.

提交回复
热议问题