Recent

Author Topic: Heaptrc unit and 128 bytes used in startup  (Read 2270 times)

jmm72

  • Jr. Member
  • **
  • Posts: 79
  • Very experienced in being a beginner...
Heaptrc unit and 128 bytes used in startup
« on: March 05, 2017, 01:03:43 am »
I've had this problem since I re-started using Lazarus this winter, with 1.6.2. I use heaptrc to seek leaks, just as I used it a while ago with 1.4.x; however whenever I'm debugging, when I exit my program, heaptrc always, and I mean always, shows an 'error' window. Most of the times it also shows a message saying '128 bytes used in startup', but other times it doesn't do so. The heap size and the free heap are always off by those 128 bytes if things went right, but I still have to look if it's really 128 (the fact that the numbers shown don't use a space as thousand separator doesn't help) in case a small leak is in the way.

I came to the conclusion that certain 128 bytes are used before the heaptrc unit comes into scope or something like that (I can imagine some inner working but I don't know the details), or that those 128 bytes aren't still freed when heaptrc does its final check. At first I just ignored it as 'one of those things', but with time it has become increasingly annoying. If those 128 bytes are normal, then I'd not want an 'error' window, unless I want a memory usage report.

I create the debug & release modes with the feature in the project options for creating those two modes, I don't touch anything else. It happens in all my projects, including any new one I create.

I've seen some stuff for interacting with the unit using and setting variables, but since the unit is not in the uses clause, the identifiers are invalid for the compiler, so I'm a bit lost on that side.

Using Lazarus 1.6.4 64 bits under Windows 7, but it also happened with 1.6.2. I'm not really sure if it happened in one of the last updates of the 1.4.x branch so I'm not counting that.

So, anyone else has this? Is it fixable? How?
Lazarus 1.6.4 + FPC 3.0.2 64bits under Windows 7 64bits
Only as a hobby nowadays
Current proyect release: TBA

Thaddy

  • Hero Member
  • *****
  • Posts: 8046
Re: Heaptrc unit and 128 bytes used in startup
« Reply #1 on: March 05, 2017, 07:38:33 am »
Do you add heaptrc by hand to your uses clause? DON'T. Use "-gh" from the fpc command line or in Lazarus "Project|Project Options|Debugger|Use Heaptrc"

See also http://wiki.freepascal.org/heaptrc or http://freepascal.org/docs-html/current/rtl/heaptrc/index.html

Note the usage example in the rtl documentation is still wrong. Instead of "uses heaptrc" it should read "{ compile this example with -gh or -glh }" or something.
In FPC trunk (maybe even 3.0.2) the  compiler will throw a "duplicate identifier HEAPTRC" error and stop if you want to do it by hand.

If you use heaptrc according to the documentation and don't use heaptrc in the uses clause, plz provide an example that replicates the issue.

Possible cause is a known one: You are probably also debugging with lineinfo. Heaptrc needs to be initialized before the lineinfo (-gl) and only the compiler can do that.

Ok, so you explained that you did not add it by hand. I suspect there is a rogue heaptrc that ended up somewhere in one of the units (not project) uses clause.
Ok, you are not using another memory manager like cmem? (heaptrc has its own memory manager)?
But please provide an example..



« Last Edit: March 05, 2017, 08:59:58 am by Thaddy »
Hamlet 1.4 (nothing wrong with the Danish, btw)

jmm72

  • Jr. Member
  • **
  • Posts: 79
  • Very experienced in being a beginner...
Re: Heaptrc unit and 128 bytes used in startup
« Reply #2 on: March 05, 2017, 12:47:16 pm »
There's no code implied. As I said, I don't add the unit to the uses section, I just use the debug mode. I use these steps, to create an application without any code:
1. File, new, application.
2. An empty form appears, the only thing in the project.
3. In Project Options, go to Compiler Options, Build Modes, use the button 'Create Debug and Release modes'.
4. Ensure the build mode is in Debug. This means -gh is enabled.
5. Run the app. The empty form will appear. Close it.
6. In my system, the heaptrc 'error' window appears with all data. This time, instead of 128, the message says '160 bytes used in startup', and the offset between heap size and free heap is 160.

I was curious about that lineinfo thingy and I did another run with -gl disabled. It compiled and ran, but the same error with 160 bytes off happened. I also tried disabling external file for symbols, and dirtying variables (using Lazarus in spanish, sorry if the options have another english name). But the behaviour continued.

I must infer that this happens to me and maybe a few others, and the majority of the people don't see the heaptrc 'error' window unless a true memory leak happens. Should I file a bug?
Lazarus 1.6.4 + FPC 3.0.2 64bits under Windows 7 64bits
Only as a hobby nowadays
Current proyect release: TBA