- Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
- Handle(TDataStd_TreeNode) aRoot = TDataStd_TreeNode::Set(aDoc->Main());
+ Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
+ Handle(TDataStd_TreeNode) aRoot = TDataStd_TreeNode::Set(aDoc->Main());
+
+ // NPAL18604: use existing label to decrease memory usage,
+ // if this label has been freed (object deleted)
+ bool useExisting = false;
+ TDF_Label aChild;
+ if (!_lastCleared.IsNull()) {
+ if (_lastCleared.Root() == aDoc->Main().Root()) {
+ useExisting = true;
+ aChild = _lastCleared;
+ _lastCleared.Nullify();
+ }
+ }
+ if (!useExisting) {
+ // create new label
+ aChild = TDF_TagSource::NewChild(aDoc->Main());
+ }