 |
GTK+ Forums Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
|
|
|
| Author |
Message |
|
|
Peter GTK+ Geek
Joined: 10 May 2008 Posts: 54
|
Posted: Sun May 18, 2008 2:34 pm Post subject: Best way for tracking memory leaks? |
|
|
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
|
Posted: Mon May 19, 2008 3:47 am Post subject: |
|
|
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 |
|
 |
|
Powered by phpBB © 2001, 2005 phpBB Group CodeBB 1.0 Beta 2
|