[fpc-pascal] gtree - Freeing a nil Root without error

Daniel Gaspary dgaspary at gmail.com
Tue Jan 7 20:58:50 CET 2014


Hi,

   gtree.TTree type has the following code:

constructor TTree.Create;
begin
  FRoot := nil;
end;

destructor TTree.Destroy;
begin
  FRoot.Free;
end;


How is possible then that the following program don't raise an error
when the destructor (via free) is called?


program Project1;
{$mode objfpc}{$H+}
uses
  Classes, gtree;
type
    TStrTree = specialize TTree<String>;
var
   tt: TStrTree;
begin
     tt:=TStrTree.Create;
     if tt.Root = nil
     then
         WriteLn('Root is nil!');
     tt.Free;
end.

Thanks,

       Daniel



More information about the fpc-pascal mailing list