--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
It's unsafe until we get rid of the implicit raw pointer <-> scoped_refptr conversion.
I'm curious what the current thinking is on functions that return refcounted objects..
On Wed, Nov 13, 2013 at 3:53 PM, Fred Akalin <aka...@chromium.org> wrote:
It's unsafe until we get rid of the implicit raw pointer <-> scoped_refptr conversion.Are there plans to actually do this?
--
Is there any reason to return raw pointers instead of scoped_refptrs for functions that are not doing a transfer of ownership (e.g., AutofillWebDataService::FromBrowserContext())?
The problem with returning a bare pointer is that the caller might not
realize it's a refcounted object, and store it without thinking about
the refcount.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
When you contrast it with the scoped_ptr case like that, I have to concur the raw pointer does imply "don't keep it".
It's unsafe until we get rid of the implicit raw pointer <-> scoped_refptr conversion.
If you did:
X* x = getX();
and getX() returns a scoped_refptr<X>, it'll be silently converted to a raw pointer, which may be invalid by the time you use it (because something else released the last ref).
So unfortunately returning raw pointers is the safer bet, since memory leaks are less bad than use-after-frees. :/
It sounds like the added reference counting of returning a
scoped_refptr potentially adds too much overhead for Android, so you
should probably return a raw pointer, assuming that's what we do in a
lot of our codebase (and I think it is).