I am playing around with the AdvTreeView (CollectionMode). I can't quite explain the immense memory consumption. I read in a directory structure with about 30.000 entries, in parallel I write information into a StringList. If I now delete the StringList, the memory consumption of the application remains almost unchanged, if I then delete the TreeView with ClearNodes, memory is released again. If I delete the TreeView first, nothing happens - only when I release the StringList again, a corresponding amount of RAM is released. MemoryLeaks are not reported. Is there still something like memory fragmentation in Delphi?
I once read in a directory structure with about 600,000 entries, which resulted in a memory consumption of about 2.9GB. If I save the tree with the Save method and then read it again with the Load method, the consumption is only 1.5GB. However, I find this 1.5GB still quite high, if I consider that the file from the SaveToFile method is just 40 MB in size.
I can understand the memory consumption of the stringlist: The file is about 90MB in size, the memory consumption increases by about 200 MB after the direct reading, which is fine, since (as far as I know) 2 bytes per character are needed (keyword UnicodeString).
Thanks and Best Regards
Collection Mode allocates a TAdvTreeViewNode collection item instance for each entry, which means that you multiply that by 600,000. It contains information from a node such as a value for each column, colors, alignment, etc... In this case I strongly suggest to use virtual mode, and map the structure via events instead.
Ok, the memory requirement of the TAdvTreeViewNode is larger than that of the TAdvTreeViewVirtualNode. So I use the virtual variant now. Since no tree has been created yet, I need to use the AddVirtualNode method. Is it correct that I can use the DataXXX fields to store some information that I can use later for the GetNodeText event? - So far it works, but is it maybe a wrong use of these fields?
Another question: Why can't I return "0" nodes in the GetNumberOfNodes event? This will throw an exception. But there are no know nodes, when this event is fired the first time ... i think ... or brings this function the TreeView in virtual mode?
Regarding my upper issue with memory fragmentation: I think it was really a memory fragmentation issue because I wrote some log data to a TStringList when building the tree. The parallel filling of the TStringList was removed, the each other blocking of the "internal free memory function" was gone.
You should not use AdvVirtualNode in combination with GetNumberOfNodes. Please just use GetNumberOfNodes and use the other node related events to add text, ... and fill up the treeview.
Hmm, I am using the node related events to add text, but the text is coming from the AdvVirtualNodes. So it seems to be a mix between virtual and collection based mode, or? Is this using the virtual mode in the right way: I have to create my own (tree) data structure where the GetNumberOfNodes & GetNodeText functions grab the data from. All nessecary AdvVirtualNodes are automatically created by the AdvVirtualTree component?
That's correct. virtual mode has less memory impact but needs to map via events on the required events such as the OnGetNumberOfNodes & the OnGetNodeText event.