Tuesday, October 30, 2007

What is Memory Leak?

I have been assigned this task to create a new API for an application to access to grab data from a global repository. Actually there is nothing special about this API, it was just a simplified version of the existing API the application was using, just that too much unnecessary data was returned which had an impact on its performance.

After making the changes and doing the benchmarking there was a performance improvement of more than 100%. Sounds good eh... Then comes the endurance part, where the API is used constantly with a stable load for a period of few days and monitoring the memory utilization during this time. Monitoring work begins, first few hours looks good, no increase in memory usage but after that the memory increased gradually after a day. So I presented this findings to my colleague which was managing this "product". She said a memory leak occured for this new API. I was thinking to myself, how could this be, this is an existing piece of code modified to be better and there's nothing new about it. If this is a problem, then the current one running in production is also in trouble. I didn't want to argue, so I checked my piece of work properly to see whether I left out anything. It looks ok, nothing missing. She mentioned that the production one is running fine and was tested to be OK previously. So we decided to load the old API to test, the same results were returned.

Uh... so now what is the problem, she decided to consult the experts in performance tests, it seems like the garbage collection was not efficient enough to perform it's job on time. Therefore causing memory not in used, not released back to the system. After doing forced garbage collection, the memory utilization was back to normal :) Well, I am happy, I learnt something new on Memory management for software applications. It was worth all the trouble and difficulty doing this test.

Definition of Memory Leak, this is a snippet from Wikipedia:
"In computer science, a memory leak is a particular kind of unintentional memory consumption by a computer program where the program fails to release memory when no longer needed. This condition is normally the result of a bug in a program that prevents it from freeing up memory that it no longer needs.

The term is meant as a humorous misnomer, since memory is not physically lost from the computer. Rather, memory is allocated to a program, and that program subsequently loses the ability to access it due to program logic flaws.

As is noted below, a memory leak has similar symptoms to a number of other problems, and generally can only be diagnosed by a programmer with access to the program source code; however many people are quick to describe any unwanted increase in memory usage as a memory leak, even if this is not strictly accurate."

No comments: