WeakReference for parent
Summary: - Use WeakReference for parent to avoid circular reference although GC will treat it Reviewed By: emilsjolander Differential Revision: D3982520 fbshipit-source-id: b0f6764aa4df3da53be51f6cb4fe2994d989afdf
This commit is contained in:
committed by
Facebook Github Bot
parent
c233bafeb2
commit
90844d62c5
@@ -117,12 +117,12 @@ namespace Facebook.CSSLayout
|
||||
{
|
||||
ForceGC();
|
||||
Assert.AreEqual(0, CSSNode.GetInstanceCount());
|
||||
TestDestructorFunc();
|
||||
TestDestructorForGC();
|
||||
ForceGC();
|
||||
Assert.AreEqual(0, CSSNode.GetInstanceCount());
|
||||
}
|
||||
|
||||
private void TestDestructorFunc()
|
||||
private void TestDestructorForGC()
|
||||
{
|
||||
CSSNode node = new CSSNode();
|
||||
Assert.AreEqual(0, CSSNode.GetInstanceCount());
|
||||
@@ -131,6 +131,45 @@ namespace Facebook.CSSLayout
|
||||
node = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDestructorWithChildren()
|
||||
{
|
||||
ForceGC();
|
||||
Assert.AreEqual(0, CSSNode.GetInstanceCount());
|
||||
TestDestructorWithChildrenForGC1();
|
||||
ForceGC();
|
||||
Assert.AreEqual(0, CSSNode.GetInstanceCount());
|
||||
}
|
||||
|
||||
private void TestDestructorWithChildrenForGC1()
|
||||
{
|
||||
CSSNode node = new CSSNode();
|
||||
Assert.AreEqual(0, CSSNode.GetInstanceCount());
|
||||
node.Initialize();
|
||||
Assert.AreEqual(1, CSSNode.GetInstanceCount());
|
||||
|
||||
TestDestructorWithChildrenForGC2(node, 1);
|
||||
ForceGC();
|
||||
Assert.AreEqual(2, CSSNode.GetInstanceCount());
|
||||
|
||||
TestDestructorWithChildrenForGC2(node, 2);
|
||||
ForceGC();
|
||||
Assert.AreEqual(3, CSSNode.GetInstanceCount());
|
||||
|
||||
node = null;
|
||||
}
|
||||
|
||||
private void TestDestructorWithChildrenForGC2(CSSNode parent, int count)
|
||||
{
|
||||
CSSNode child = new CSSNode();
|
||||
Assert.AreEqual(count, CSSNode.GetInstanceCount());
|
||||
child.Initialize();
|
||||
Assert.AreEqual(count + 1, CSSNode.GetInstanceCount());
|
||||
|
||||
parent.Insert(0, child);
|
||||
child = null;
|
||||
}
|
||||
|
||||
private void ForceGC()
|
||||
{
|
||||
GC.Collect(GC.MaxGeneration);
|
||||
|
Reference in New Issue
Block a user