[webkit-dev] What's the difference RefPtr and OwnPtr?

Eric Seidel eric at webkit.org
Tue Dec 13 09:30:22 PST 2011


OwnPtr holds a pointer and calls "delete" on that pointer when it goes
out of scope.
Just like RefPtr, you can .release() the pointer from an OwnPtr, into
a PassRefPtr.
PassOwnPtr functions similarly to an OwnPtr (in that it will delete
its pointer when it goes out of scope)
except when you assign a PassOwnPtr to another OwnPtr it gives up its
pointer (.release()s itself).

Think of OwnPtr like RefPtr, except for singularly-owned objects
instead of reference-counted objects.
Think of PassOwnPtr as OwnPtr's analog to PassRefPtr.

See the original files for more information:

http://trac.webkit.org/browser/trunk/Source/JavaScriptCore/wtf/OwnArrayPtr.h
http://trac.webkit.org/browser/trunk/Source/JavaScriptCore/wtf/OwnFastMallocPtr.h
http://trac.webkit.org/browser/trunk/Source/JavaScriptCore/wtf/OwnPtr.h
http://trac.webkit.org/browser/trunk/Source/JavaScriptCore/wtf/OwnPtrCommon.h
http://trac.webkit.org/browser/trunk/Source/JavaScriptCore/wtf/PassOwnArrayPtr.h
http://trac.webkit.org/browser/trunk/Source/JavaScriptCore/wtf/PassOwnPtr.h
http://trac.webkit.org/browser/trunk/Source/JavaScriptCore/wtf/PassRefPtr.h
http://trac.webkit.org/browser/trunk/Source/JavaScriptCore/wtf/PassTraits.h

On Tue, Dec 13, 2011 at 3:18 AM, Paul Hsu <pochun.hsu at gmail.com> wrote:
> Hi all,
>
> I'm a newbie in webkit development.
>
> I found a great article about 'RefPtr and PassRefPtr' here.
> http://www.webkit.org/coding/RefPtr.html
>
> But there's no document about 'OwnPtr and PassOwnPtr'.
>
> I would like to ask what's the difference RefPtr and OwnPtr?
>
> How to use OwnPtr and PassOwnPtr?
>
> Need your help.
>
> --
>     Paul Hsu
>     pochun.hsu at gmail.com
>
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
>


More information about the webkit-dev mailing list