I hate being the bearer of bad news, but I doubt that you can reduce the time it takes to complete the tree of objects. 10 years ago or so, I co-developed SQL Accord in VB6, an application that compares databases. Thus, you can imagine that you keep thousands of objects in memory (for example, tables / view / sproc / etc definitions) to be able to quickly compare them.
The initial design for storing these items in collections fell to the floor due to problems raised by the OP. The culprit is the garbage collection COM - it should clear the moment when you set the object to Nothing / Null, and then, most likely, it needs to defragment the memory space - this takes time.
My solution (painful at that time) was to convert all objects to TYPE structures and convert collections to type arrays. Then I created manager objects to work with arrays / types, etc ...
Despite the fact that the code smells when you look at it, I got a 10-fold increase in performance. What for? Since TYPE structures go on the stack, and objects go on the heap, where it is much cheaper to manage them.
Angryhacker
source share