-
Looking for Memory Leak Advice
Apart from buying BoundsChecker or any of the other tools to track down memory leaks. Does anyone have any advice or tips from your years of programming experience to offer on how to track down the causes of memory leaks?
I find that the big dump that happens at the end of a program does not typically lend any useful clues as to where or what was allocated that was not freed. I find that I have to back track and comment out sections of code until through the process of elimination and trial-and-error, I am able to narrow down where the problem is. And since this is usually at the bottom of the To-Do list, the memory leaks are not plugged.
-
if the program is interactive, you can bring up a tool like the task manager in windows or top in unix and try to see if some sequence of steps takes a chunk of memory. You can also watch it and see if it happens regularly like every 10 seconds or whatnot.
If the leak is large, look for large allocations (maybe do a search on every new statement in the program and look for new blah[100000] or the like). If it is small, you can try the reverse and look for a function that is called a lot, maybe a function that returns a pointer as these can be written such that the caller must deallocate...
If all else fails you can try to match every new to a delete statement, with a script or the like, and at least eliminate some of the possibilities and highlight things to check. If the programmers play swicharoo with pointers everywhere (x = y, ... delete y, x is also deleted sort of games) then this will not work. If most of the code is sane, it will.
-
BoundsCcheker and many other memory diagnostics tools often have false alarms, i.e., they report memory leaks that aren't really leaks. The best thing to do is reduce the amount of manual memory allocation in your programs and use standard containers instead. It's a very general piece of advice. If you can provide more details about the nature of your application, which memory management policy it uses etc., I'll be able to give more pinpointed guidelines. The bottom line is this: better design is tremendously more helpful than using memory leak detectors.
Danny Kalev
-
I have learned that you need to have a
to go along with every
I wonder if I need something to go along with my calls.
-
possibly -- you will have to look at the documentation or if you have none, try it in a stub program and see if that is a leak?
-
 Originally Posted by Complete
. . .
I wonder if I need something to go along with my calls.
After you do not more need the object created with CoCreateInstance, I think you have to free it by calling Release function:
Code:
SomeObject * object;
CoCreateInstance(. . ., &object);
. . .
object->Release();
I hope this makes sense.
-
Every new should has one delete.
Be aware of transfer ownership to another during passing arguments.
I hope this help.
Similar Threads
-
By esi-eric in forum Java
Replies: 3
Last Post: 02-24-2005, 06:58 PM
-
By David K. in forum Careers
Replies: 0
Last Post: 01-15-2001, 09:21 PM
-
By Kevin Burton in forum .NET
Replies: 12
Last Post: 10-09-2000, 10:29 AM
-
By David K. in forum Careers
Replies: 0
Last Post: 10-06-2000, 05:29 PM
-
By John Grandy in forum VB Classic
Replies: 0
Last Post: 04-08-2000, 08:35 PM
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks