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

Tony Whyman tony.whyman at mccallumwhyman.com
Thu Oct 6 15:12:31 CEST 2016


On 06/10/16 11:08, Graeme Geldenhuys wrote:
> I've seem some
> COM Interface code where they had to resort to using raw Pointer types
> etc to try and avoid reference counting and causing unexpected memory
> leaks.
I have also seen plenty of examples of poor coding with classes, but the 
fact that someone writes bad object oriented programs doesn't mean that 
object oriented is a poor programming technique. Likewise, poor 
programming using com interfaces doesn't invalidate the use of com 
interfaces.

When you work with interfaces, there are two issues to consider:

1. How easy is the interface to use
2. How do you write the underlying classes.

To me, the first rules out delegated interfaces and COM. Even advanced 
level programmers will get it wrong and you will never get an easy to 
use interface with this combination. It looks like a design error that 
came from Delphi and was copied by FPC. However, if you rule out this 
combination, COM does make for what seems to be a very intuitive easy to 
use interface, in the same way that AnsiStrings are easy to use.

On the other hand, implementing the classes that provide a com interface 
does require some skill and is not for everyone.



More information about the fpc-pascal mailing list