Where does your "65000 memory blocks" statistic comes from?
When a class instance is Created, the following class method is called before executing the Create
method of the class (from _ClassCreate
global function, which ensures that the instance is created only once, for all Create nested calls):
class function TObject.NewInstance: TObject;
Which calls GetMem
to get memory from the heap, and then the following method:
class function TObject.InitInstance(Instance: Pointer): TObject;
This InitInstance
method will:
- Call FillChar() to put all the previously allocated memory to 0;
- Initialize the Interface Table of the object.
The methods (i.e. not the interfaces) are defined in the class type itself, not during class instance creation.
There is no "register" containing what you say.
You have access to the object memory address by its self variable, or by trans-typing its variable to a pointer:
var O: TObject;
begin
O := TObject.Create;
writeln('O memory address is ',pointer(O));
O.Free;
end;
And before Delphi 2010 and its enhanced RTTI, you don't have access to all methods and fields of an object. Only published properties and methods are accessible to your code. But you must use RTTI. See TypInfo.pas unit.