views:

103

answers:

1

I have an applet that consome quite a lot of Memory. If a user opens multiple tabs with a webpage that has the applet, they get an OutOfMemoryException. This can be explained by the fact that browsers use just one instance of a virtual machine. Is there any way I can prevent this?

The OutOfMemoryException can't really be caught, since it can happen (almost) everywhere...

+1  A: 

I would recommend doing some profiling of the applet to see what you can trim down, assuming opening lots of tabs with the applet is a standard use case. You will need to run the applet very lean.

You may also want to use the applet lifecycle methods more to your advantage. When the applet page loses focus, I believe the applet's stop() method is called. Once the applet page comes back into view it start() should be called. You could use the applet stream persistence to share your running data across the different tabs, saving it out on stop() and loading it back in on start()... not sure this is a great solution, but it might work.

Other than "because they can" is there any legitimate reason for a user to have a bunch of tabs with your applet running in each? If it's just a far-out test case, you may just want to do what you can and then document the issue.

Good luck.

cjstehno
I don't expect my users to run more than 1 applet, but indeed, they can... I'm not sure about stop and start, but it sounds like more complicated work which could ultimately cause more problems. I've seen that browsers restart all of the applets when an OutOfMemoryError occurs. The memory is now allocated inside the init method so I'm catching the error now and I display an error message. This is not even close to full proof, but it will show the error message (unless the user is very impatient).
Jaap