Delphi interface reference counting
Posted on 2002-07-22
Please explain how Delphi manages interface reference counting. It seems like it automatically calls _AddRef when I assign a value to an iref, and calls _Release when it goes out of scope (my explicit _Release results in Access Violation). When I pass an iref to some procedure (var or out parameter), again Delphi knows that it needs to call _Release. But how? The procedure might have not assigned anything. The same seems to happen with irefs - class members: when I call _Release and set iref to nil in, say, FormDestroy, it works, but then I get Access Violation as if Delphi calls _Release once more.