Re: Interface Question
- From: Rob Kennedy <me3@xxxxxxxxxxx>
- Date: Tue, 10 Oct 2006 23:15:13 -0500
Hans-Peter Diettrich wrote:
Rob Kennedy wrote:So if you free the object by calling Free, you need to be certain that there are no dangling interface references for that object. If there are, then _AddRef or _Release will eventually be called for the object that has already been destroyed, and that's the same problem you have even if you _don't_ "disable" reference counting.
Just _AddRef and _Release cannot cause problems, because the non-counting versions don't access the object. Calling other methods may cause trouble, of course.
In Delphi, an interface reference is a pointer to a field inside an object. When the object gets destroyed, any pointers to its fields become invalid. When the memory gets re-used in another allocation, the memory formerly occupied by the field may get overwritten with something else, so the interface reference is no longer pointing to a pointer to a function table, and thus a call to _AddRef will fail as the program tries to fetch the function's address from the function table.
--
Rob
.
- Follow-Ups:
- Re: Interface Question
- From: Hans-Peter Diettrich
- Re: Interface Question
- References:
- Interface Question
- From: alanglloyd@xxxxxxx
- Re: Interface Question
- From: Maarten Wiltink
- Re: Interface Question
- From: Hans-Peter Diettrich
- Re: Interface Question
- From: Maarten Wiltink
- Re: Interface Question
- From: Hans-Peter Diettrich
- Re: Interface Question
- From: Rob Kennedy
- Re: Interface Question
- From: Hans-Peter Diettrich
- Interface Question
- Prev by Date: Re: Interface Question
- Next by Date: Re: Interface Question
- Previous by thread: Re: Interface Question
- Next by thread: Re: Interface Question
- Index(es):