Sign in Join

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

Mailing lists / fpc-pascal / 2016-01

Objects, open arrays and memory leaks

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

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

Santiago A.

Hello:

I'm using Free Pascal Compiler version 3.0.0 [2015/11/16] for i386

I'm getting memory leaks (on winXP and Linux) . I have tracked to this.

(Note: they are objects, not classes)

type
TArray=object
  InnerList:array of integer;
  constructor Init;
end;
constructor TArray.Init;
begin
 SetLength(InnerList,10);
end;
procedure test;
var
  obj:TArray;
begin
  obj.init;
  obj.init;
end;

When I call twice the constructor "init" there is a memory leak. The open array of first init is not freed;
init just sets the length of an open array to 10. I mean, no pointer or object created.
I know open array are implemented pointers but I supposed that runtime would take care of it, so I was using the constructor to clear object and start from scratch.

What I am missing?

Saludos Santiago A.