No memory leak with free of base class

Can somebody explain why there isn't any memory leak here ?

type ttest=class(tcomponent)
    fa: string;
    property a: string read fa write fa;

procedure TFrmMain.Button1Click(Sender: TObject);
test: ttest;
while true do
    test := ttest.create(nil);
    test.a := 'errror!';
    tcomponent(test).free;   //<--- no mem. leak here?!?
Who is Participating?
First. Each memoryblock allocated by the standard Memorymanager contains before the memoryblock an Integer that storres the allocated size of the Block. This size might be slightly greater than the requested memorysize. On deallocation the MM decrement the Pointer by 4 and get so this Value (called SizeFlags).
Second. For each Class the Compiler store into the codesegment an Record that describe the Class. This record contains the VMT = Virtual Method Table, the DMT = Dynamical Method Table, the Interfacetable of the supported Interfaces of the class, some classmember like a pointers or datas for the ParentClass, ClassName,  Instancesize, Properties and published methods, and to the TypeInfo for the Class. This TypeInfo IS the RTTI = Run Time Type Information to every Type that we use. After all the Compiler generates a big Tree of Classinformations linked to the second big Tree of Typeinformations. Now, on destruction of any Instance we can easily get all needed Information to clear any Instance-Fields that pointed to Interfaces or referencecounted Types like Strings, dynm. Arrays, Variants and other this.

You should take a look, suppose You can read assembler, into System.pas and study such procedures as .FreeInstance or _FinalizeRecord;

TObject.Free calls internal TObject.Destroy; and .Destroy is virtual. A destructor calls .FreeInstance; and this Method use some RTTI member to cleanup the Instance, they Interfaces, reference counted Fields, like Strings, dyn. Arrays, and finally calls Freemem(Self, Self.InstanceSize) to free the Instance it self.
and Self.InstanceSize is ignored because the size of the allocated block is stored inside the allocated block.
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Yes, if we assume as underlaying Memorymanager the Borland Standard one.
kogerAuthor Commented:
Could you describe a little more.
Free is called to TComponent's, but there is no string propery in TComponent. How does TComponent know how to clear the property and free it?
kogerAuthor Commented:
Now that's an impressive answer :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.