[Lazarus] Finding memory leaks
Graeme Geldenhuys
mailinglists at geldenhuys.co.uk
Sun Oct 25 01:45:10 CEST 2015
On 2015-10-24 13:51, Aradeonas wrote:
> So how can I find out what is the problem?
Hence I recommend to anybody to develop any code with -gh and -gl
enabled as standard. It is *much* easier to fix a memory leak the minute
you created it - so you know exactly which few lines caused the problem.
Anyway... this is what I do
1. Compile you program with -gh and -gl and -O- compiler parameters.
2. Run as little as possible of the program then quit. Check if leaks
are caused.
3. It is easier if you dump the heaptrace output to file so review.
4. Start at the top. The first line is normally the cause of the leak,
and the lines below is the backtrace of how you got to that point. This
is not exact science - it takes a clear mind and attention to detail to
spot the leaks.
5. The heaptrace reports all memory leaks, but concertrate on one at a
time. Many times fixing one leak reduces the leak count a lot.
6. Repeat from step 2 until all leaks are solved.
Some leaks are easy to spot and fix, others can take very long to find.
There is no "easy fix" for this (existing code). The "easy fix" for
newly written code, is to always develop with -gh and -gl enabled.
Regards,
- Graeme -
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/
My public PGP key: http://tinyurl.com/graeme-pgp
More information about the Lazarus
mailing list