CDP Forum Forum Index CDP Forum
NOTE: The forum is being replaced by support.icd.no
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Strategies for finding memory leaks

 
Post new topic   Reply to topic    CDP Forum Forum Index -> C++ programming
View previous topic :: View next topic  
Author Message
Imbrondir



Joined: 07 Jun 2007
Posts: 44

PostPosted: Mon 14 Jun 11:24:33 2010    Post subject: Strategies for finding memory leaks Reply with quote

I have a CDP application that consistantly exhaust memory of a small PC with 256mb or 512mb ram after about 2-4 weeks. This is obviously due to a memory leak, but since the application is quite complex and the leak accumulates slowly it's quite hard to find and test it. Do you have any special strategy for debugging such a problem?
Back to top
View user's profile Send private message
Rune



Joined: 14 Mar 2007
Posts: 25
Location: Norway

PostPosted: Mon 14 Jun 11:44:04 2010    Post subject: Reply with quote

There are several ways to find memory leaks:

- Go through the code, check that there is a delete for every new
- Make sure that new[] is matched with delete[]
- if you're dealing with lists or similar, make sure they don't grow forever, so set a max-size where you start deleting elements and maybe even write out warnings or set alarms (this may be the case with you?)
- If you're running on Windows, you can use the CrtCheckMemory() function
- Check the API function documentation and see if any functions you are using require that you to handle memory-cleanup yourself.
- write your own new/delete operators and track memory leaks yourself Smile

<todo: Add more here>
_________________
Best Regards,
Rune Espeseth
Industrial Control Design AS
Back to top
View user's profile Send private message Visit poster's website
Imbrondir



Joined: 07 Jun 2007
Posts: 44

PostPosted: Thu 24 Jun 11:41:38 2010    Post subject: Reply with quote

Thanks for the input.

After some failed experiments, I decided to try port the program to CDPLinux so I could run it under the free Valgrind profiler. It took a bit of work, but once properly compiled and running, finding the leaks was very much a walk in the park! Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    CDP Forum Forum Index -> C++ programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group