<div dir="ltr"> After some further investigation I can now confirm that one of the leak is caused by the following code in <span style="color:rgb(0,0,0)">QQmlObjectCreator::createInstance(), </span><span style="color:rgb(0,0,0)">qqmlobjectcreator.cpp</span>:<br><br><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(128,0,0)">sharedState</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">allJavaScriptObjects</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span>QV4<span style="color:rgb(0,0,0)">::</span>QObjectWrapper<span style="color:rgb(0,0,0)">::</span>wrap<span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,0,0)">v4</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">instance</span><span style="color:rgb(0,0,0)">);</span>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">++</span><span style="color:rgb(128,0,0)">sharedState</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">allJavaScriptObjects</span><span style="color:rgb(0,0,0)">;</span></pre>
<pre style="margin:0px;text-indent:0px"><br></pre> But the reason is still unknown<br><div><br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Nov 15, 2015 at 10:19 PM, Liang Jian <span dir="ltr"><<a href="mailto:jianliang79@gmail.com" target="_blank">jianliang79@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div> Hello everyone, I checkout qt 5.6 branch yesterday in my windows 10 x64 machine, I build it and run my program and see many leaks. Then I use <span>C++ Memory Validator</span> to find the source of the leaks, I can now confirm the leaked objects are QtSharedPointer::ExternalRefCountData which are created in <span style="color:rgb(128,0,128)">QQmlObjectCreator</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(0,0,0)">createInstance(), </span><span style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">qqmlobjectcreator.cpp Line 1049</span>, below is the call stack printed by</span><span style="color:rgb(0,0,0)"> <span>C++ Memory Validator</span>:<br><br> Qt5Cored.dll QtSharedPointer::ExternalRefCountData::getAndRef : [d:\qt5\qtbase\src\corelib\tools\qsharedpointer.cpp Line 1337]<br> <br> Qt5Qmld.dll QWeakPointer<QObject>::QWeakPointer<QObject><QObject> : [d:\qt5\qtbase\src\corelib\tools\qsharedpointer_impl.h Line 706]<br> <br> Qt5Qmld.dll QPointer<QObject>::QPointer<QObject> : [d:\qt5\qtbase\src\corelib\kernel\qpointer.h Line 65]<br> <br> Qt5Qmld.dll QQmlObjectCreator::createInstance : [d:\qt5\qtdeclarative\src\qml\qml\qqmlobjectcreator.cpp Line 1049]<br> 1044 : QQmlData *ddata = QQmlData::get(instance, /*create*/true);<br> 1045 : ddata->rootObjectInCreation = true;<br> 1046 : sharedState->rootContext->isRootObjectInCreation = false;<br> 1047 : }<br> 1048 : <br> 1049 : sharedState->allCreatedObjects.push(instance);<br> 1050 : } else {<br> 1051 : Q_ASSERT(typeRef->component);<br> 1052 : Q_QML_OC_PROFILE(sharedState->profiler, profiler.update(typeRef->component->fileName(),<br> 1053 : context->url(), obj->location.line, obj->location.column));<br> 1054 : if (typeRef->component->compilationUnit->data->isSingleton())<br> Qt5Qmld.dll QQmlObjectCreator::create : [d:\qt5\qtdeclarative\src\qml\qml\qqmlobjectcreator.cpp Line 197]<br> <br> Qt5Qmld.dll QQmlComponentPrivate::beginCreate : [d:\qt5\qtdeclarative\src\qml\qml\qqmlcomponent.cpp Line 863]<br> <br> Qt5Qmld.dll QQmlComponent::beginCreate : [d:\qt5\qtdeclarative\src\qml\qml\qqmlcomponent.cpp Line 812]<br> <br> Qt5Qmld.dll QQmlComponent::create : [d:\qt5\qtdeclarative\src\qml\qml\qqmlcomponent.cpp Line 772]<br> <br> Qt5Quickd.dll QQuickView::continueExecute : [d:\qt5\qtdeclarative\src\quick\items\qquickview.cpp Line 486]<br> <br> Qt5Quickd.dll QQuickViewPrivate::execute : [d:\qt5\qtdeclarative\src\quick\items\qquickview.cpp Line 127]<br> <br> Qt5Quickd.dll QQuickView::setSource : [d:\qt5\qtdeclarative\src\quick\items\qquickview.cpp Line 256]<br><br><br></span></div><span style="color:rgb(0,0,0)"> All the leaked </span><span style="color:rgb(0,0,0)">QtSharedPointer::ExternalRefCountData objects are allocated in </span><span style="color:rgb(0,0,0)">the line<br> sharedState->allCreatedObjects.push(instance);<br> then some other code path will also use QPointer (contained in some structures allocated by v4mm) to track the same object 'instance' and I guess the QPointer wasn't properly destructed which will cause the </span><span style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">QtSharedPointer::ExternalRefCountData not deleted</span>.<br></span></div><span style="color:rgb(0,0,0)"> I have investigated this issue for nearly one day, but I can't find which code cause the leak, this is a non-trivial leak, I hope somebody can help to find the source of the leak. thanks!<br></span><div><div><span style="color:rgb(0,0,0)"><br></span></div></div></div>
</blockquote></div><br></div>