Reputation: 423
Actually, I know it's necessary to free the memory allocated with malloc(), but I wonder if I can know there is some memory left being not collected if I forget to collect it with free().
Upvotes: 0
Views: 303
Reputation: 59
You can use a tool like valgrind. Check out this video on how to use it, courtesy of Harvard's CS50 available on edx. It gives a very good explanation on how to use it, as well as some examples on both correct and incorrect code.
Upvotes: 1
Reputation: 3000
In addition to valgrind answers, you may link your executables against Boehm GC – C garbage collector that may run in leak detection mode.
https://en.wikipedia.org/wiki/Boehm_garbage_collector
http://www.hboehm.info/gc/
http://www.hboehm.info/gc/leak.html
Upvotes: 1
Reputation: 1
What you are trying to do is impossible. Just keep track of all the memory you allocated and erase it when needed
Upvotes: -1