Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-10

Leak narrowed down

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Tobias Giesen

Hello,

I have narrowed the leak down. It's not in FPC. It's in the LCL or most likely in the Carbon interface. It leaks memory outside of the FPC heap. Probably some CFStrings or other Carbon data types.

It's caused be the following line:

Lb.Width:=Lb.Canvas.GetTextWidth(Lb.Caption);

For now I can avoid doing this. If I come up with a fix, I'll post it to the Lazarus list.

Cheers,
Tobias

Reply by email

Jonas Maebe
to Tobias Giesen
Tobias Giesen wrote 10 lines
I have narrowed the leak down. It's not in FPC. It's in the LCL or most likely in the Carbon interface. It leaks memory outside of the FPC heap. Probably some CFStrings or other Carbon data types. It's caused be the following line: Lb.Width:=Lb.Canvas.GetTextWidth(Lb.Caption); For now I can avoid doing this. If I come up with a fix, I'll post it to the Lazarus list.

Before starting your program, set the following environment variable:

export MallocStackLogging=1

Then, once the program is running and has leaked memory, run

leaks nameofyourprogram

It will print all allocation sites of memory blocks that are no longer reachable. Note that it can also give false positives, but given the fact that you already identified one culprit it shouldn't be too difficult to extract the relevant ones.

Jonas

Reply by email

Tobias Giesen
to Jonas Maebe
Jonas wrote
export MallocStackLogging=1 Then, once the program is running and has leaked memory, run leaks nameofyourprogram

Thanks for this tip! It is very interesting, however in this situation it does not detect the lost memory.

At this point I have to give up on GetTextWidth - I will avoid it for now. Maybe next year the problem can be solved. I will send a note to the Lazarus list and submit a bug report, provided I can confirm the issue with a minimal testing program.

Cheers,
Tobias

Reply by email

Luca Olivetti
to Tobias Giesen

Al 28/10/10 22:12, En/na Tobias Giesen ha escrit:

Show quoted text 5 lines
At this point I have to give up on GetTextWidth - I will avoid it for now. Maybe next year the problem can be solved. I will send a note to the Lazarus list and submit a bug report, provided I can confirm the issue with a minimal testing program.

FWIW, I've had similar issues several times under Linux/gtk/gtk2: heaptrc reports no leaks but memory usage keeps growing, until the OOM kills the application.
I suppose that this kink of issue is really difficult to debug for Lazarus developers, since apparently there's nothing blatantly wrong. Consider yourself lucky that you found the culprit and can avoid it.

Bye

Luca

Reply by email

Jonas Maebe
to Tobias Giesen: Thanks for this tip! It is very interesting, however in this situation it does not detect…
Tobias Giesen wrote 8 lines
Jonas wrote: > export MallocStackLogging=1 > Then, once the program is running and has leaked memory, run > leaks nameofyourprogram Thanks for this tip! It is very interesting, however in this situation it does not detect the lost memory.

You can also run the program under valgrind with its default tool (memcheck). It will trace all memory allocations (rather than scanning the heap for potential pointers to memory blocks) and should be able to pinpoint where the unfreed allocations are happening.

Jonas

Reply by email

Andrew Brunner
to Tobias Giesen: Thanks for this tip! It is very interesting, however in this situation it does not detect…
Show quoted text 10 lines
> Then, once the program is running and has leaked memory, run > leaks nameofyourprogram Thanks for this tip! It is very interesting, however in this situation it does not detect the lost memory. At this point I have to give up on GetTextWidth - I will avoid it for now. Maybe next year the problem can be solved. I will send a note to the Lazarus list and submit a bug report, provided I can confirm the issue with a minimal testing program.

There are two instances in the past that I had with working with GetTextWidth to the point where I started with Delphi's canvas and traced into their code and derived my own from theirs. If you are needing the feature then compile FPC with DEBUG=1, recompile Lazarus with DEBUG=1 (I think), then trace into the LCL/FPC code and take a look around.

It could be with the string it could be with the Device Context used to draw the text and see its width. It could be the Handle to the font object not being de-allocated. Do you use try handling with finally SetLength(Str,0)?

If you place a counter inside that routine, how many times is it called? That may help too.

Reply by email