[fpc-pascal] Problem with objects

Santiago A. svaa at ciberpiula.net
Wed Dec 23 18:41:21 CET 2015


El 23/12/2015 a las 18:24, Jonas Maebe escribió:
> Santiago Amposta wrote:
>
>
> This is a bug in FPC 2.6.4 (it did not initialise managed fields of
> parent objects for child objects that do not declare extra managed
> fields). It is fixed in FPC 3.0.
>

I have used constructors as a workaround now I have a problem of memory
leaks.

 TSimpleArrayString=object
    List:array of String;
    constructor Init;
 end;

 { TDerivedArrayString }

 TDerivedArrayString=object(TSimpleArrayString)
    other_field:integer;
    constructor Init;
 end;

constructor TDerivedArrayString.Init;
begin
  // nothing
end;

constructor TSimpleArrayString.Init;
begin
  // nothing
end;

procedure TestSimple;
var
 A:TSimpleArrayString;
begin
  a.init;
  setLength(A.List,16);
end;

procedure TestDerived;
var
 A:TDerivedArrayString;
begin
  a.init;
  SetLength(a.list,16);
  SetLength(a.list,0);  // If i comment this line, when I finish the
program, the debug says there are unfreed blocks
end;

In TDerivedArrayString I need to manually set the length of the list to
zero. If I don't, the memory is not freed, but in TSimpleArrayString it
frees memory.

Is it also a known bug of 2.6.4?

-- 
Saludos

Santiago A.
svaa at ciberpiula.net




More information about the fpc-pascal mailing list