From 5319190a069ce6657577718a72e645dad45be0af Mon Sep 17 00:00:00 2001 From: xqian6 Date: Thu, 31 May 2012 16:54:04 +0800 Subject: Fix memory leak caused by CSSRuleList wrapper Accessing cssrulelist in javascript will create a new CSSRuleList object and wrapper JS object. The wrapper JS object will be added into hidden array in parent JS object which is alive during the whole execution. Thus memory leak happens (CSSRuleList in webkit, wrapper object and weak global handle in v8). Cherry pick 2 patches from upstream solves the problem: http://trac.webkit.org/changeset/90949 This patch changes hidden reference from array to named property. So new wrapper will replace old wrappper. But the memory leak still exists because the CSSRuleList wrapper will be added into an object group of current document. So they will still be alive during execution. http://trac.webkit.org/changeset/91256 This patch avoids to adding CSSRuleList wrapper into document object group. Combined with the first patch, it can resolve the memory leak problem. Change-Id: Icb523db52963726f27b6c02596822cfb6e8d5049 Author: Vitaly Repeshko Signed-off-by: Xi Qian Signed-off-by: Shuo Gao Signed-off-by: Bruce Beare Signed-off-by: Jack Ren Author-tracking-BZ: 32630 --- Source/WebCore/bindings/v8/V8HiddenPropertyName.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'Source/WebCore/bindings/v8/V8HiddenPropertyName.cpp') diff --git a/Source/WebCore/bindings/v8/V8HiddenPropertyName.cpp b/Source/WebCore/bindings/v8/V8HiddenPropertyName.cpp index d83573f..2909269 100644 --- a/Source/WebCore/bindings/v8/V8HiddenPropertyName.cpp +++ b/Source/WebCore/bindings/v8/V8HiddenPropertyName.cpp @@ -31,6 +31,9 @@ #include "config.h" #include "V8HiddenPropertyName.h" +#include +#include + namespace WebCore { #define V8_AS_STRING(x) V8_AS_STRING_IMPL(x) @@ -39,12 +42,22 @@ namespace WebCore { #define V8_DEFINE_PROPERTY(name) \ v8::Handle V8HiddenPropertyName::name() \ { \ - static v8::Persistent* string = createString("WebCore::V8HiddenPropertyName::" V8_AS_STRING(name)); \ + static v8::Persistent* string = createString("WebCore::HiddenProperty::" V8_AS_STRING(name)); \ return *string; \ } V8_HIDDEN_PROPERTIES(V8_DEFINE_PROPERTY); +static const char hiddenReferenceNamePrefix[] = "WebCore::HiddenReference::"; + +v8::Handle V8HiddenPropertyName::hiddenReferenceName(const char* name) +{ + Vector prefixedName; + prefixedName.append(hiddenReferenceNamePrefix, sizeof(hiddenReferenceNamePrefix) - 1); + prefixedName.append(name, strlen(name)); + return v8::String::NewSymbol(prefixedName.data(), static_cast(prefixedName.size())); +} + v8::Persistent* V8HiddenPropertyName::createString(const char* key) { v8::HandleScope scope; -- cgit v1.1