Clean-up parent / owner reference of children during clonning
Summary: This diff cleans up the parent / owner references for children of ReactShadowNode / YogaNode during cloning. The reason of this behavior is to avoid retaining every generation of trees during cloning. This fixes a memory leak detected when running the ProgressBarExample.android.js in catalyst app Reviewed By: fkgozali Differential Revision: D8019894 fbshipit-source-id: b0d38f0c836ffec534f64fa1adbd7511ecf3473d
This commit is contained in:
committed by
Facebook Github Bot
parent
2ce219ef42
commit
cdb1ee21a0
@@ -1,8 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014-present, Facebook, Inc.
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
* LICENSE file in the root directory of this source tree.
|
* file in the root directory of this source tree.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
@@ -185,6 +186,11 @@ public class YogaNode implements Cloneable {
|
|||||||
clonedYogaNode.mOwner = null;
|
clonedYogaNode.mOwner = null;
|
||||||
clonedYogaNode.mChildren =
|
clonedYogaNode.mChildren =
|
||||||
mChildren != null ? (List<YogaNode>) ((ArrayList) mChildren).clone() : null;
|
mChildren != null ? (List<YogaNode>) ((ArrayList) mChildren).clone() : null;
|
||||||
|
if (clonedYogaNode.mChildren != null) {
|
||||||
|
for (YogaNode child : clonedYogaNode.mChildren) {
|
||||||
|
child.mOwner = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
return clonedYogaNode;
|
return clonedYogaNode;
|
||||||
} catch (CloneNotSupportedException ex) {
|
} catch (CloneNotSupportedException ex) {
|
||||||
// This class implements Cloneable, this should not happen
|
// This class implements Cloneable, this should not happen
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) 2014-present, Facebook, Inc.
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
* LICENSE file in the root directory of this source tree.
|
* file in the root directory of this source tree.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Yoga.h"
|
#include "Yoga.h"
|
||||||
@@ -243,6 +244,9 @@ YGNodeRef YGNodeClone(YGNodeRef oldNode) {
|
|||||||
oldNode->getConfig(),
|
oldNode->getConfig(),
|
||||||
node != nullptr,
|
node != nullptr,
|
||||||
"Could not allocate memory for node");
|
"Could not allocate memory for node");
|
||||||
|
for (auto &item : oldNode->getChildren()) {
|
||||||
|
item->setOwner(nullptr);
|
||||||
|
}
|
||||||
gNodeInstanceCount++;
|
gNodeInstanceCount++;
|
||||||
node->setOwner(nullptr);
|
node->setOwner(nullptr);
|
||||||
return node;
|
return node;
|
||||||
|
Reference in New Issue
Block a user