Yes, I realise that. But consider this:
- IUnknown::QueryInterface returns an IntPtr to an interface. The
reference count is 1.
- GetTypedObjectForIUnknown is called to generate a RCW. It generates a
new RCW, now the reference count is 2.
- I use Marshal.ReleaseComObject to release the original reference.
That's all fine. We have 1 reference to the interface, that of the RCW.
Now consider this situation.
- IUnknown::QueryInterface returns an IntPtr to an interface. The
reference count is N.
- GetTypedObjectForIUnknown is called to generate a RCW. It has already
generated a RCW for this object in the past so the reference count is
unchanged.
- I use Marshal.ReleaseComObject to release the original reference. This
decreases the count back to N-1, prematurely freeing the object.
Am I misunderstanding something fundamental here?
Regards
Steve
> Per the MSDN documentation, the object returned is a runtime callable
> wrapper.
[quoted text clipped - 11 lines]
>> not increase the reference count on the COM object. How do I know when to
>> Release()?
Michael Phillips, Jr. - 26 Mar 2007 16:09 GMT
COM rules always apply.
For unmanaged COM objects, you are responsible for the reference count
bookeeping per the COM guidelines.
For managed COM objects that use the RCW mechanism, the RCW handles the
reference count bookeeping per the COM guidelines.
> Yes, I realise that. But consider this:
>
[quoted text clipped - 35 lines]
>>> not increase the reference count on the COM object. How do I know when
>>> to Release()?