Interface IUnknown Release Object

Everything else that doesn't fall into one of the other PB categories.
User avatar
mk-soft
Always Here
Always Here
Posts: 5401
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Interface IUnknown Release Object

Post by mk-soft »

Microsoft wrote
Remarks
When the reference count on an object reaches zero, Release must cause the interface pointer to free itself. When the released pointer is the only existing reference to an object (whether the object supports single or multiple interfaces), the implementation must free the object.
Note that aggregation of objects restricts the ability to recover interface pointers.
With the objects ActiveScript or ActiveScriptParse the objects are already released with Ref-Counter 1 and a call from release to zero leads to a memory access error.

Does MS not take its own doku seriously, or do I interpret something wrong here?
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Interface IUnknown Release Object

Post by Mijikai »

Found this on stackoverflow:
1) The examples you refer to have to be getting their COM interface pointers from somewhere.
This would be by making COM calls, e.g., CoCreateInstance() and QueryInterface().
These calls are passed the address of your raw pointer and set that raw pointer to the appropriate value.
If they weren't also implicitly AddRef'ed, the reference count might be 0 and COM could delete the associated COM object
before your program could do anything about it. So such COM calls must include an implicit AddRef() on your behalf.
You are responsible for a Release() to match this implicit AddRef() that you instigated with one of these other calls.
https://stackoverflow.com/questions/393 ... -questions
User avatar
mk-soft
Always Here
Always Here
Posts: 5401
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Interface IUnknown Release Object

Post by mk-soft »

I checked again...

CoCreateInstance of ActiveScript starts with Ref-Counter 1 to probably prevent an automatic delete.
So also with Ref-Counter 1 the object is released again.

So all is well :wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply