[fpc-pascal] A serious Memleak using delegates/implements (was: Delegate Interface class does not seem to be referenced counted)

stdreamer stdreamer at freemail.gr
Fri Oct 7 19:32:22 CEST 2016

On 07/10/2016 18:33 μμ, Marcos Douglas wrote:
> We don't need "clean up properly" instances that is interface-based.
> If this solve the problem for contained objects, I'll do it!
> BUT, if I do this I can forget all about  TContainedObject or
> TAggregatedObject? If I can't, this not make sense.

OK this needs a bit more information.

The interface variable is only a half measure. It assumes and expects 
that the container (the object that has a delegation) will always get 
destroyed after all references to the delegated interface are released. 
It does not check for it and it leaves everything to the programmer. If 
the contained interface needs the container to function properly then a 
number of of exception will be raised as soon as the container gets freed.
The TContainedObject on the other hand makes sure that the container can 
not be destroy as long as there are references on the contained 
interface which is a much safer solution.

I have used both with success in the past I still prefer the 
TContainedObject approach for this little extra piece of mind that it 
provides me.

More information about the fpc-pascal mailing list