diff --git a/poincare/include/poincare/tree_reference.h b/poincare/include/poincare/tree_reference.h index 41b3cf121..ef60f88a8 100644 --- a/poincare/include/poincare/tree_reference.h +++ b/poincare/include/poincare/tree_reference.h @@ -185,7 +185,9 @@ public: assert(oldChildIndex >= 0 && oldChildIndex < numberOfChildren()); TreeReference oldChild = treeChildAtIndex(oldChildIndex); TreePool::sharedPool()->move(oldChild.node()->next(), newChild.node()); - newChild.node()->retain(); + if (!p.isDefined()) { + newChild.node()->retain(); + } TreePool::sharedPool()->move(TreePool::sharedPool()->last(), oldChild.node()); oldChild.node()->release(); }