ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
There's no real way to test if there's a memory leak. You just have to look at the code or notice that your program just keeps taking more and more memory for no reason.
A memory leak is technically when a pointer that has been allocated to a block of memory in the heap (also called global memory by some) has not been freed or the pointer variable has gone out of context without freeing the memory. In that case there is no way of referring to the allocated memory or freeing it. This is called a memory leak. The memory allocated will be locked off (unusable by other programs).
1) if malloc/new(nothrow) returns NULL, memory allocation failed, pointer points nowhere.
2) for every successful new/malloc you should eventually call a delete/free
If you aren't going to do any class allocation programming in c++, use malloc and free, the will make your life easier. there is no free/free[] crap, like with c++ delete
however, there are tools that check memory leaks in programs, I use them in a windows environment (rational purify) but there should be some for the LINUX environment.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.