> What you are worried about is the life time of the object pointed to by > a inteface pointer. There is a guaranteed that all XPCOM object will > exist until the last reference to them is owned. So, in your example, > the caller had to have a reference to this object.
Ahh. Naive question. The caller is invoking the method _synchronously_, that is its subsequent code (the one behind the fun call, potentially calling Release()) gets not executed before the function returns even if the function body is preempted in the middle. Further, I guess it makes sense for the client/caller to have references in thread local storage (private heap) or on the thread's stack (local variable) wherever possible. A function does not > need to explictly AddRef() an |in| interface pointer. OK. Got it. > > Now this guarantee calls for all code to handle your |ifcPtr| > "correctly". Basically, it means that no one can call delete() directly > on this interface pointer. They may only use Release() to end the life > time of an object. If the entire system obeys this rule, then there is > no problem. Clear, don't bypass stuff. > > Of course, there is a whole field of understand about reference count > balancing and ownership. It is tricky to understand and harder to get > right. (or maybe that is the other way around.) There are plenty of > place in the mozilla source base which have sticky ownership problems. > (do an LXR searce for "KungFoDeathGrip"). Puh. I will have a look into this. Guess cyclic ownerships are part of this mantra, or is it zen or kungfo? It strangly reminds me of the entity relationship complexities one can encounter in a model as soon as one leaves the road of strict hierarchies. add physical and logical chronologies and you're ready for the psychiatrist .. > > In general, if the system stick to only addref and release of xpcom > objects, there is no problem. I have traced too many problem down where > parts of a system treated an interface pointer with AddRef/Release, and > other parts decided to call delete directly. This basically results in > what you are talking about, in the middle of your function, |ifcPtr| > suddenly becomes garbage. I promise to never bypass refcounting .. and i will eat my vegetables ;) > > Does this make sense? Thanks alot for clearifying. Tobias > > Doug Turner > [EMAIL PROTECTED] >
