I am using version 8.3.20083.1009.
I am loading the tree using the basic following method:
ultraTree1.ImageList = _imgs; // _imgs is ImageList previously loaded with about 3500 images.
UltraTreeNode node = new UltraTreeNode(key, title);node.LeftImages.Add(3);node.LeftImages.Add(3001);ultraTree1.Nodes.Add(node);
I first noticed the issue when I had as few as 400 nodes in the tree. Watch memory usage (I am using Process Explorer) while you scroll (via paging). As you scroll memory usage for the test application quickly builds from about 45 MB to 1.5 GB and then gets collected back down to 45MB. While the memory is at its highest point the images in the visible nodes dissappear. They remain gone until you take enough scrolling actions to trigger a memory collection back down to 45MB then they reappear.
Is this a known issue? Is there a workaround other than triggering garbage collection everytime I scroll? Is there something I might be doing wrong to cause this? I am just loading up the tree as described about and scrolling. I verified that the memory does not climb upwards unless I perform a scroll action.
Thanks.
First of all, let me thank you for posting this !!
I too have a tree with lots of images loaded onto the LeftImages collection. Since i was testing with few hundred records i couldnot actually notice the memory variations. But after looking at this post i tried the tree with 30K records and i could see what you are referring to.
Based on few other posts on memory leaks in wintree, i have made sure that i dispose all the nodes that i create and especially dispose each and every image used.
Yeah, that is what I figured was going on. I originally tested by assigning the image rather than using an image list but it was significantly slower which is why I went to the image list method.
What is the most performant way to have a node show two images?
The ImageList component appears to provide clones of the images included in its Images collection when you access them via the indexer. For example, if you run the following code:
ImageList imageList = new ImageList();imageList.Images.Add( Image.FromFile( "c:\\whatever.bmp" ) );Image image1 = imageList.Images[0];Image image2 = imageList.Images[0];bool same = Image.ReferenceEquals(image1, image2);
you will see that even though the same ordinal position within the collection was accessed, they are not the same instances.
3500 images is an awful lot and given the behavior I cited in the previous paragraph, it isn't going to take long to max out your GDI+ resources, which is most likely the reason images are disappearing. I suggest you grab the images out of the ImageList (if you must use an ImageList) and stash them somewhere, so you can access them without new instances being created every time you do.