[fpc-pascal] Interface performance

Tony Whyman tony.whyman at mccallumwhyman.com
Fri Nov 11 12:58:23 CET 2016


On 11/11/16 10:59, Ryan Joseph wrote:
> What does memory management even mean for interfaces? I never allocate an interface I just implement it in a class so what’s there to be freed? All these crashes I’m getting suggest memory is being trashed by the compiler at some point without my knowledge. I never explicitly allocate an interface like an object so there’s nothing to manage in my mind.
May be that the best way to understand an interface is to think of it as 
a pointer to a class's VMT (or at least a VMT derived from the class's 
VMT) plus a reference to the object 'self'). When you call a method that 
belongs to an interface, the underlying code simply performs a VMT 
lookup and calls the method at the selected table location and provides 
the 'self' reference to the method. The result is then no different to a 
normal method call.

Interfaces do exist independent of objects. They depend on underlying 
object instances for their implementation.

An interface continues to work as long as the 'self' reference is valid. 
Once the underlying object is freed then the 'self'' reference becomes 
invalid and the interface no longer works.

With CORBA, you are responsible for creating and freeing the object 
instances providing an interface. Under COM, you are still responsible 
for creating the objects. They are automatically freed when the 
interface (and any copies) go out of scope.



More information about the fpc-pascal mailing list