[fpc-devel] FreeInstance

Ryan Joseph ryan at thealchemistguild.com
Wed Aug 1 17:27:45 CEST 2018



> On Aug 1, 2018, at 9:17 AM, Sven Barth via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
> 
> Search the compiler's source for the string 'FREEINSTANCE'; you'll find two locations, one in ngenutil and one in psub. The latter is the one you want. 
> 

Yeah, this is the first place I looked but current_structdef is always nil so it never progresses past that point.

Is this test program not enough to get FreeInstance called? 

program test;
var
	obj1: TObject;
begin
	obj1 := TObject.Create;
	obj1.Free;
end.


===========

    function generate_bodyexit_block:tnode;
      var
        srsym : tsym;
        para : tcallparanode;
        newstatement : tstatementnode;
        oldlocalswitches: tlocalswitches;
      begin
        result:=internalstatements(newstatement);

        if assigned(current_structdef) then
          begin
            { Don't test self and the vmt here. The reason is that  }
            { a constructor already checks whether these are valid  }
            { before. Further, in case of TThread the thread may    }
            { free the class instance right after AfterConstruction }
            { has been called, so it may no longer be valid (JM)    }
            oldlocalswitches:=current_settings.localswitches;
            current_settings.localswitches:=oldlocalswitches-[cs_check_object,cs_check_range];

            { a destructor needs a help procedure }
            if (current_procinfo.procdef.proctypeoption=potype_destructor) then
              begin
                if is_class(current_structdef) then
                  begin
                    srsym:=search_struct_member(current_structdef,'FREEINSTANCE');

Regards,
	Ryan Joseph




More information about the fpc-devel mailing list