I’m running an algorithm that generates a huge tree, the least runnable result came out with 2,069,073 nodes, and took up 3gigs of memory.
But that won’t do!
My question is, are there any good methods or practices to dynamically recycle any unneeded nodes when running?
EDIT: “I’m running a multiprocessor scheduling algorithm with 2 machines and 10 jobs on each machine.”
Maintaining your own pool of nodes … if that is what you mean … won’t help at all. If the nodes become reachable, the garbage collector will find them. A poorly implemented object pool can stop this happening, making the problem worse.
I suspect that your problem is that you are leaking objects. If there are nodes in the tree that are no longer needed, you should be able to get rid of them by assigning null to the relevant field or array element of the parent node. Assuming that your node graph is really a tree, that should be sufficient to disconnect the node and subnodes from the main tree, and (if it is now unreachable) make it eligible for garbage collection.
Another possibility is that there is another kind of memory leak somewhere in your code.