I have a visualization that renders ~50MB table data in X-Y axis layout. I need to change the table data when users choose another data file. But the problem is that, even I used
m_vis.removeGroup("groupname");
m_vis.addTable("groupname", table);
m_vis.run("actionname1");
m_vis.run("actionname1"); ....
Or I create a new Visualization and Display, remove the previous Display from the common container, like a JPanel, and add this newly created Display.
These two method both work fine in terms of creating a nice image. BUT!!!!
After rendering a few data files, it has a out of memory problem. I watch the memory usage info. I found that the previous visualization and data are not cleaned by the garbage collection function. So each image and data are still in memory, and soon it claimed all memory reserved by JVM.
After digging into other threads in the Sorucefore' Prefuse forum, I think I find the answer which partially (90%) solve my problem. Here is the thread that discuss the nearly same problem.
The only difference is that they used graph as base data, while I am using Table as base data. The reason to cause the out of memory problem is that Display will NOT automatically destroy its buffered off-screen image and activities. Also unused data will NOT automatically lost its reference to the TupleSet and registered listeners. Since these data still has valid references, JVM cannot collect the memory they took.
In the beta version, Heer fix the above problems by adding a new method in Display, called reset(), which will set m_offscreen to NULL, and clean queue, and by adding a removeAllGraphListener() in Graph and removeAllTableListener() in Table to clean up all registered listeners to base data structure. So here is the solution to reclaim memory unused by a Display. You need to create a public method to do the cleanup, e.g. a method like
public void cleanup()
Then do the following in this method.
1. Display.setVisualization(null)
2. Display.reset();
For the base data used in Visualization in this Display. Do these.
1. Table( or Graph).removeAllTable(or Graph)Listener();
2. Table( or Graph).clear(); After call this cleanup method, do garbage collection, e.g. Runtime.getRuntime.gc() or System.gc(); The majority of unused memory will be relocated.
In my case, there is still a few un-release memory, ~10MB. That is why I said, it is partially (90%) solved.


