How sure are you that a memory leak is actually happening? Normally, the task manager will not be very useful here, since it cannot determine how much memory belonging to your process is actually allocated. Even freed memory is still relevant to your process and can be used in subsequent periods by memory management (usually a library in the form of a malloc-like system).
Use a tool like mallocdebug, valgrind, purify, etc. to find out if a memory leak is really happening. These tools will replace the malloc implementation with a new one that tracks allocated memory and report memory that is not freed up after the process is complete.
Note. On most systems, memory freed from the process does not return to the system until the process exits. However, it is available for new distributions from the same process.
source share