Why does my finished program still owe eight bytes?
· #1i made one TObject in a tiny 64 bit console program and never called Free
the heap report has this line
1 unfreed memory blocks : 8but the program finished so who is keeping the receipt
i made one TObject in a tiny 64 bit console program and never called Free
the heap report has this line
1 unfreed memory blocks : 8but the program finished so who is keeping the receipt
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:
fpc -gh -gl receipt.pas
./receiptLet 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.
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:
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.
I deleted the report file to save space. The next run made another one. This is a determined accounting system.
the unfreed count is zero now
i thought Free meant the price
Deleting the receipt does not return the object.
Forum rules 1 to 10 apply. Yes, to you.