On Aug 8, 11:12 am, "Igor Tandetnik" <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > This morning while browsing I noticed this message about scope. > > >http://groups.google.com/group/mozilla.dev.embedding/browse_thread/th... > > > I had thought that all nsCOMPtr references were automatically de- > > referenced once they go out of scope. So the following within a > > method will orphan settings when said method is exited? Does everyone > > trust the GC'ing or are they setting the reference to 0 explicitly? > > Are you talking about C++, or about Java? The thread you cite is about > Java XPCOM binding, but the code below looks C++ to me. There's no GC in > C++. > > > nsCOMPtr<nsIPrintSettings> settings; > > printing->GetGlobalPrintSettings((nsIPrintSettings**)&settings); > > This should be > > nsCOMPtr<nsIPrintSettings> settings; > printing->GetGlobalPrintSettings(getter_AddRefs(settings)); > > And yes, nsCOMPtr destructor will call Release() on the interface > pointer when 'settings' variable goes out of scope. > > > PS Those google validation characters are ridiculous!!! > > I must admit I have no idea what you are talking about. > > Igor Tandetnik
Yes the thread was Java but XPCOM is simply a wrapper over the C++ code is it not? The example code is C++ and I meant inherent scoping of variables, so a variable declared in within a method should go out of scope. The reason the code was written that way was to determine if the variable pointer settings will automatically go out of scope or I have to explicitly call addref. So the answer is "settings" will orphan unless I use addref. In which case addref would handle the out of scope condition. The google validation characters before posting, I have to enter them to post this message. That's what I meant, which I can never read. :) _______________________________________________ dev-embedding mailing list [email protected] https://lists.mozilla.org/listinfo/dev-embedding
