if i'm calling a interface method which takes an interface parameter,
do i have to AddRef it for thread-safety reasons within the implementing
function body to make sure the object behind the passed in interface
parameter will not go away till the end of the function call ??

in the nsCOMPtr's user manual, it reads ..

"There is no need to AddRef parameters, as they are guaranteed to live
as long as the function call."

that puzzles me: of course a "nsISupports* ifcPtr" in _itself_ will live
that long, because e.g. C++ guarantees it .. but for the obj it points
to there is no guarantee of any kind, isn't it?

if i'm in a single-threaded app, obviously there's no problem. but if
the app is multi-threaded, the implementing function body could be
preempted in the middle and some other code could call Release ()
causing the obj to fade away. if the body gets executed again, its
ifc parameter will dangle.

thanks for your hints,
Tobias

ps: ok, maybe its more a general COM question .. still i'm lost ;)


Reply via email to