Sign in Join

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

Mailing lists / fpc-devel / 2002-06

Memory consumption

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Zbigniew Kuczbański

Hi,

This is very simple program.
I really dont know why HeapTrace unit show memory consuption I use FPC ver. 1.06, platform Win32.

Best regards
Zbigniew Kuczbański

program PCLH8;
{$mode objfpc}
uses HEAPTRC, sysutils, crt;
var
  szDevNbr      : array[0..255] of Char;
  sDevName      : String;
begin
{ This is testing program. Unit HEAPTRC shows, that is memory leakage.
   I really don't know why??????
}
//  SetHeapTraceOutPut('PCLH8.mem');
    sDevName:='A testing string';
    StrPCopy(szDevNbr,sDevName);
    writeln('szDevNbr: ',szDevNbr);
    writeln('szDevName: ',sDevName);
  Halt(0);
end.

Reply by email

Jonas Maebe
to Zbigniew Kuczbański
Zbigniew Kuczbański wrote 15 lines
var szDevNbr : array[0..255] of Char; sDevName : String; begin { This is testing program. Unit HEAPTRC shows, that is memory leakage. I really don't know why?????? } // SetHeapTraceOutPut('PCLH8.mem'); sDevName:='A testing string'; StrPCopy(szDevNbr,sDevName); writeln('szDevNbr: ',szDevNbr); writeln('szDevName: ',sDevName); Halt(0); end.

The reason is that because of the halt() statement, the temporary ansistrings that have been generated can't be released. It's strange that a temporary ansistring is generated though. It's for the "StrPCopy(szDevNbr,sDevName);" statement. sDevName is a normal shortstring, but the compiler insists on first converting it to an ansistring and then uses the strpcopy(pchar,ansistring) routine (instead of just calling strpcopy(pchar,shortstring). Strange.

Jonas

Reply by email