Unused interface reference is not destroyed

后端 未结 2 1228
轻奢々
轻奢々 2021-02-09 06:47

i had another bug in my app caused by careless usage of Delphi interfaces. When i pass an interface to a procedure which ignores that argument, the instance is never freed. See

2条回答
  •  南笙
    南笙 (楼主)
    2021-02-09 07:20

    Add a guid to you ITest declaration

    ITest = interface
    ['{DB6637F9-FAD3-4765-9EC1-0A374AAC7469}']
        procedure Test;
    end;
    

    Change the loop to this

    for x in list do
        x.UseTestOrNot(Tester.Create as ITest);
    

    The GUID is neccesary to be able to use as

    Test.Create as ITest makes the compiler to add the release where the created object goes out of scope.

提交回复
热议问题