Hello all,
I have an unbound UltraTree (v16.1) which is populated using the code below. This works well. Yet, my RAM piles up each time i populate the tree. I guess that the GC is not firing. Which is the right way to "clean" alle nodes off the tree to refill it with new data, using the same columnset as before? resetNodes or Nodes.Clear? According to help, both "remove all nodes".. but not from RAM?
Thanks
Martin
int intMinLevel = dstTreeBuilder.MyHierarchy.Min(r => r.cteLevel);
int intMaxLevel = dstTreeBuilder.MyHierarchy.Max(r => r.cteLevel);
utrMyHierarchy.BeginUpdate();
utrMyHierarchy.Nodes.Clear();
utrMyHierarchy.ResetNodes();
UltraTreeNode node;
//generate nodes by Level (first root, then children of root etc)
for (int intCurrentLevel = intMinLevel; intCurrentLevel <= intMaxLevel; intCurrentLevel++)
{
var CurrentLevelRows = dstTreeBuilder.MyHierarchy.Where(r => r.cteLevel == intCurrentLevel).OrderBy(r => r.ID);
foreach (var CurrentLevelRow in CurrentLevelRows)
node = new UltraTreeNode(CurrentLevelRow.ID.ToString(CultureInfo.InvariantCulture));
node.Override.ColumnSet = oColumnset;
foreach (UltraTreeNodeColumn col in oColumnset.Columns)
node.SetCellValue(col, CurrentLevelRow[col.Key]);
}
//Place Node in hierarchy
if (intCurrentLevel == intMinLevel)
//Root
utrMyHierarchy.Nodes.Add(node);
else
//Non-Root
UltraTreeNode parentNode = utrMyHierarchy.GetNodeByKey(CurrentLevelRow.F_Parent_ID.ToString(CultureInfo.InvariantCulture));
parentNode.Nodes.Add(node);
utrMyHierarchy.EndUpdate();
Your welcome. I am glad that helped.
Thank you, that fixed it!
Hello,
You should call ResetNodes to remove all nodes in the tree. Performing Clear removes the current collection and it's root node. However this doesn't completely dispose them because we can't assume the same node won't be used else where.
You can dispose all the nodes this way:
static void DisposeNode( UltraTreeNode node ){ List<UltraTreeNode> list = new List<UltraTreeNode>(); list.Add ( node );
if ( node.HasNodes ) GetNodes( node.Nodes, ref list );
for ( int i = 0, count = list.Count; i < count; i ++ ) { list[i].Dispose(); }}
static void GetNodes( TreeNodesCollection nodes, ref List<UltraTreeNode> list ){ for ( int i = 0, count = nodes.Count; i < count; i ++ ) { UltraTreeNode node = nodes[i]; list.Add( node );
if ( node.HasNodes ) GetNodes( node.Nodes, ref list ); }}
thanks for your reply.
There are no images involved.
Removing nodes the way you suggest would need a level-based approach, removing the nodes in the deepest level first, then proceed upwards towards the root, right? I've assumed that one of the commands (Clear/ResetNodes) would have done this...
Regards
Try calling Remove.
eg.
UltraTree.Nodes.Remove(node)
Are you assigning images to your nodes? It's possible some resources aren't getting cleaned up that the previous nodes were using.