Why do interface implementations based on TComponent leak memory?

前端 未结 3 1848
面向向阳花
面向向阳花 2021-02-04 04:09

This Delphi code will show a memory leak for an instance of TMyImplementation:

program LeakTest;

uses
  Classes;

type
  MyInterface = interface
  end;

  TMyIm         


        
3条回答
  •  终归单人心
    2021-02-04 04:25

    A component is supposed to be owned and destroyed by something else, typically a form. In that scenario, reference count is not used. If you pass a component as an interface reference it would be very unfortunate if it was destroyed when the method returns.

    Therefore, reference counting in TComponent has been removed.

提交回复
热议问题