Web Inspector: Native Memory Instrumentation: reportLeaf method doesn't report the...
[WebKit-https.git] / Source / WebCore / inspector / InspectorMemoryAgent.cpp
index 882ef5084bff14ec60383b0f22f341ae9f822b23..58d2bdb7d01c5337d27df1319356c6e1c18ab785 100644 (file)
@@ -333,11 +333,31 @@ void InspectorMemoryAgent::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo)
     info.addMember(m_page, "page");
 }
 
+namespace {
+
+class FrontendWrapper : public HeapGraphSerializer::Client {
+public:
+    explicit FrontendWrapper(InspectorFrontend::Memory* frontend) : m_frontend(frontend) { }
+    virtual void addNativeSnapshotChunk(PassRefPtr<TypeBuilder::Memory::HeapSnapshotChunk> heapSnapshotChunk) OVERRIDE
+    {
+        m_frontend->addNativeSnapshotChunk(heapSnapshotChunk);
+    }
+private:
+    InspectorFrontend::Memory* m_frontend;
+};
+
+}
+
 void InspectorMemoryAgent::getProcessMemoryDistributionImpl(bool reportGraph, TypeNameToSizeMap* memoryInfo)
 {
     OwnPtr<HeapGraphSerializer> graphSerializer;
-    if (reportGraph)
-        graphSerializer = adoptPtr(new HeapGraphSerializer(m_frontend));
+    OwnPtr<FrontendWrapper> frontendWrapper;
+
+    if (reportGraph) {
+        frontendWrapper = adoptPtr(new FrontendWrapper(m_frontend));
+        graphSerializer = adoptPtr(new HeapGraphSerializer(frontendWrapper.get()));
+    }
+
     MemoryInstrumentationClientImpl memoryInstrumentationClient(graphSerializer.get());
     m_inspectorClient->getAllocatedObjects(memoryInstrumentationClient.allocatedObjects());
     MemoryInstrumentationImpl memoryInstrumentation(&memoryInstrumentationClient);
@@ -355,6 +375,8 @@ void InspectorMemoryAgent::getProcessMemoryDistributionImpl(bool reportGraph, Ty
     if (graphSerializer) {
         memoryInstrumentation.addRootObject(graphSerializer.get());
         graphSerializer->finish();
+        graphSerializer.release(); // Release it earlier than frontendWrapper
+        frontendWrapper.release();
     }
 
     m_inspectorClient->dumpUncountedAllocatedObjects(memoryInstrumentationClient.countedObjects());