On 8/29/12 8:14 PM, Samuel wrote:
> The idea of recycling Jmol instances seems like poor form to me. I think
> it would make more sense to have a Jmol manager which
> activates/deactivates Jmol instances as necessary. In my rewrite of the
> Notebook front-end, I actually created a JavaScript "class" for Jmol
> instances but did not go as far as to create a manager. My code may not
> be copy-paste reusable into the Jmol library but with that approach I
> believe it would be a small step to create a manager class and hook
> things up correctly. You can see my work
> here:
https://github.com/samuela/sagenb/blob/master/sagenb/data/sage/js/jmol.js
>
Isn't that basically what I was saying? Have some way of managing a
pool of jmol instances. The reason for a pool is to prevent there from
being too many jmol instances open at once, since we've had big memory
problems from too many applets on the page. We have to do some sort of
memory management/recycling for java here.
On the other hand, Jonathan---did the memory problem go away when we
hide (versus destroyed) the applets? In other words, if I'm running out
of Java memory, and I hide all the applets, does that free up the java
memory? I don't think it does, but it seems like someone tested this a
long time ago. If merely hiding an applet clears its claim on memory,
then sure, recycling instances seems to be too much work.
What I had in mind is that a cell, when it wanted a jmol instance, would
ask the jmol manager for an instance and give the manager a DOM element
in which to put the applet. The manager would see if it had any
available instances, and if not, create a new applet and stick it in the
right spot.
Then, before a cell deleted its output, it would "free" the jmol
instance by calling the manager. The manager would move the applet out
of the cell's output region, clear the jmol data, and hide the applet
somewhere. The manager would consider this instance an available instance.
In the case that the manager had reached some set number of active
instances (or even better, when it realized the java memory was running
low), it could forcibly get the longest-idle instance (it'd have to keep
track of that somehow). The manager would sleep the instance, reclaim
the applet, and give it to the requesting cell.
Thanks,
Jason