Xingjun Wang
Xingjun Wang

Reputation: 423

Memory leak detection and analysis tool

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

Answers (4)

strontivm
strontivm

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

user3125367
user3125367

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

nikedem1
nikedem1

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

quesyKing
quesyKing

Reputation: 148

Valgrind would be your best bet

http://valgrind.org/

Upvotes: 4

Related Questions