[webkit-dev] Why Page::setMainFrame use PassRefPtr type parameter?
pattin.shieh
xytsoft at gmail.com
Sat Nov 28 00:09:48 PST 2009
Look at this:void Page::setMainFrame(PassRefPtr<Frame> mainFrame).
Why use PassRefPtr? Infact,change to following will work same:
void Page::setMainFrame(Frame *mainFrame)
1).Look into the function source code:
m_mainFrame = mainFrame; --> call "operator=(T* optr)",reference count
+1
It mean that if change to "Frame *mainFrame" ,will call mainFrame->ref();
2).Using "PassRefPtr<Frame> mainFrame":
m_mainFrame = mainFrame; --> call "operator=(const PassRefPtr<T>&
o)",reference count no change
But,reference count was changed when the function is called:
page->setMainFrame(this); --> call "PassRefPtr(T* ptr) : m_ptr(ptr) {
if (ptr) ptr->ref(); }", reference count +1
So,The "PassRefPtr<Frame> mainFrame" and the "Frame *mainFrame" cause same
reference count.
But use "PassRefPtr<Frame>" will call new operation!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20091128/16d85833/attachment.html>
More information about the webkit-dev
mailing list