GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Best way for tracking memory leaks?

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
Peter
GTK+ Geek


Joined: 10 May 2008
Posts: 54

PostPosted: Sun May 18, 2008 2:34 pm    Post subject: Best way for tracking memory leaks? Reply with quote

Any suggestion how to track down memory leaks?
What are the main things to watch to avoid memory leaks?
I am using GTK with Glade 2


Peter
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 495
Location: Portland, OR USA

PostPosted: Mon May 19, 2008 3:47 am    Post subject: Reply with quote

It can be tricky. The easiest way for me is to make sure I never take any shortcuts (meaning look it up or ask in a mailing list if I dont' know what to do) and make sure that you free memory on any variable that:

- Is a return value from a function that returns a "newly allocated" anything
- Is a pointer to an object that has a _free() function
- Is a pointer to a struct that you allocated with g_new, g_slice_new, etc.
- Is a pointer to an object that you don't know if it should be free... look it up.

There are tools too. It can be tricky though because it can be an art to know what "looks" like memory leaks in GTK and what truely are memory leaks in your application. I use Valgrind as a memory profiler and pretty much ignore errors that don't seem to explicitly come from my program.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP