Skip to content

Commit 41036a3

Browse files
Fixed memory leak with shared V8 runtimes (Issue ClearFoundry#107).
1 parent 985cde1 commit 41036a3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

ClearScript/V8/ClearScriptV8/V8ContextImpl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ V8ContextImpl::~V8ContextImpl()
737737
Dispose(m_hHostIteratorTemplate);
738738
Dispose(m_hHostDelegateTemplate);
739739
Dispose(m_hHostObjectTemplate);
740+
Dispose(m_hTerminationException);
740741
Dispose(m_hAccessToken);
741742
Dispose(m_hAccessTokenName);
742743
Dispose(m_hCachePropertyName);

ClearScriptTest/BugFixTest.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,35 @@ public void BugFix_VBScript_PropertyPut_CrossEngine_VBScript()
19011901
BugFix_VBScript_PropertyPut_CrossEngine();
19021902
}
19031903

1904+
[TestMethod, TestCategory("BugFix")]
1905+
public void BugFix_SharedV8RuntimeLeak()
1906+
{
1907+
using (var runtime = new V8Runtime())
1908+
{
1909+
using (runtime.CreateScriptEngine())
1910+
{
1911+
}
1912+
1913+
runtime.CollectGarbage(true);
1914+
var heapSize = runtime.GetHeapInfo().TotalHeapSize;
1915+
1916+
for (var i = 0; i < 500; i++)
1917+
{
1918+
using (runtime.CreateScriptEngine())
1919+
{
1920+
}
1921+
1922+
if ((i % 25) == 24)
1923+
{
1924+
runtime.CollectGarbage(true);
1925+
}
1926+
}
1927+
1928+
runtime.CollectGarbage(true);
1929+
Assert.IsFalse(runtime.GetHeapInfo().TotalHeapSize > (heapSize * 1.5));
1930+
}
1931+
}
1932+
19041933
// ReSharper restore InconsistentNaming
19051934

19061935
#endregion

0 commit comments

Comments
 (0)