views:

192

answers:

2

This question is about a Java JTree or a Window .Net Tree (Winforms) or an Adobe Flex Tree.

In a client-server application (for Flex it's Web, really), I have a tree with hierarchical data (in a Windows Explorer type interface). Right now I lazily load up the tree as the user requests more data from the server. This is fine and will work up to about 750K nodes (empirically tested on .Net Winforms and Adobe Flex), but after that it gets sluggish. But the databases grow fast (mostly because users can paste in huge amounts of nodes) and a database of 20 million nodes is not at all unlikely.

Should I be releasing data from the tree when a branch is collapsed so the Garbage Collector can release the memory? This is fine, but what if the users are not efficient and don't collapse branches? Should I do a memory management module that goes around closing branches that haven't been touched in a while?

This all seems like a lot of work so as not to not run out of memory.

Edit: Should I release data on node collapse? If so, when? The weak-object cache idea is good, but should I just continue filling up the UI until it busts (maybe it's not a bad idea)?

+1  A: 

in most frameworks i've seen, the tree structure itself is fairly efficient, but if you have a non-trivial object at each tree leaf it quickly adds.

the easiest would be not to store anything at the tree leaves, but on the render/draw/update/whatever method, pick your object from a weak-ref cache. if it's not there, load from the server. the trick is not to keep any other reference to the object, only the weak one on the cache. that way, it will be still available, but collected when necessary.

Javier
Thanks for that answer. It's an interesting point. Currently I do something like that for the non-tree data (the data associated with the nodes).
Yar
+1  A: 

If the users don't collapse branches, then I guess they're going to be scrolling through 750K to 20M nodes, right? Seems rather inefficient to me from a user POV. So, the problem may well be self-enforcing.

Will Hartung
Interesting point. On the other hand, I'm thinking about non-tree structures that might work. Working on PHP recently in Eclipse has convinced me that the Tree structure itself is pretty annoying for large numbers of nodes.
Yar
Okay, but my remaining question is IF I should release data on node collapse.
Yar