Why does my finished program still owe eight bytes?

Go down

Why does my finished program still owe eight bytes?

· #1

i made one TObject in a tiny 64 bit console program and never called Free

the heap report has this line

text
1 unfreed memory blocks : 8

but the program finished so who is keeping the receipt

Re: Why does my finished program still owe eight bytes?

· #2

Heaptrc records allocations and releases. It reports memory your program did not release before shutdown. The operating system reclaiming a terminated process does not make the allocation history balanced.

For this bare TObject on your 64-bit build, eight bytes is plausible. Other classes and targets have different sizes. Do not turn that number into a rule about objects.

Compile the console test with heap tracing and line information:

bash
fpc -gh -gl receipt.pas
./receipt

Let the compiler insert heaptrc through -gh. Do not add the unit by hand. The heap tracing documentation explains the option.

Read the error message. Then read it again.

Re: Why does my finished program still owe eight bytes?

· #3

Give the object a clear owner in your code. For a local object, this complete program pairs construction with cleanup even if the work raises an exception:

pascal
program Receipt;
{$mode objfpc}{$H+}
var
  Item: TObject;
begin
  Item := TObject.Create;
  try
    WriteLn(Item.ClassName);
  finally
    Item.Free;
  end;
end.

Create it before entering the try block. If construction fails, there is no successfully created object for this block to free.

Re: Why does my finished program still owe eight bytes?

· #4

I deleted the report file to save space. The next run made another one. This is a determined accounting system.

Re: Why does my finished program still owe eight bytes?

· #5

the unfreed count is zero now

i thought Free meant the price

Re: Why does my finished program still owe eight bytes?

· #6

Deleting the receipt does not return the object.

Forum rules 1 to 10 apply. Yes, to you.

Go up

Sign in to reply