|
-
October 6th, 2004, 03:31 AM
#1
Finding a memory leak
We have a memory leak in our application.
I have instrumented the application code such that every malloc (size and address), every realloc new size and address) and every free(address) is logged to a file.
I got loads of data that i need to anaylse and see if the leak is detected.
However would like to hear some expert comments on the approach before i spend time on writing code to get results out of this data file.
Let me know other methods to find the leak. Tools like Purify did not detect any leak at all.
-
October 6th, 2004, 04:18 AM
#2
Re: Finding a memory leak
(I am assuming you are talking Windows Development here)
For memory leaks I have used BoundsChecker with usually very good results (that is, it found the leak and gave me a call stack).
I don't have any experience with Purify so I can't tell how much better or worse BoundsChecker are than Purify in this aspect.
Also, there is a utility called GlowCode that some coders love.
Now, at another place I worked I had to find a very difficult memory leak. This company was migrating to .NET so they didn't think that it was worth the money to get boundschecker just for this. So it was up to me to fix it without BC.
What I did was this:
1. I managed to figure out that the leaked objects were allocated with GlobalAlloc.
2. I used the Detour library (http://www.research.microsoft.com/re...s/default.aspx) to inject code at every call to GlobalAlloc and GlobalFree.
3. I created a call stack at every GlobalAlloc.
4. Using a std::map I kept track of allocated and freed handles.
5. When the program terminated I traversed the map for all non-freed handles and reported the call stack.
I actually found the error using this method but it took some time.
You have already done lots of steps already. If you have it as row based text files I would try to import these files into an SQL-database i.e. SQL Server or MS Access (I wouldn't use MS Access as a db but it is actually good at correlating rows in files) and build a couple of SQL statements to find mallocs that don't have frees. The problem is once you found it you need to figure which line in your code that explicitly or implicitly called malloc but not free (here a call stack is of great help).
A critical part in all this : Is it really malloc that causes the leak? There are other kinds of leaks. If it is, then you're on the right track (I think).
Still my recommendation would be: Check out GlowCode (www.glowcode.com) or BoundsChecker (www.compuware.com) (I am slightly biased towards BC but their website sucks! It's like they don't want to sell BC to me. GlowCode OTOH used to offer a trial).
Hope this was some help to you.
-
October 6th, 2004, 09:05 AM
#3
Re: Finding a memory leak
-
October 6th, 2004, 09:27 AM
#4
Re: Finding a memory leak
I've used Purify very extensively in the past with great success so I'm a bit surprised that it didn't detect any leaks at all ... I assume you had all the Purify settings cranked up correctly? BTW what are the symptoms that you are seeing, is it that memory usage is continually increasing as the application runs?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|