Applet OutOfMemoryError

M

Mark

Hi all,

I have this java applet that shows 3D objects in a browser. The applet
interacts with javascript, users can choose objects for viewing by
clicking on a hyperlink.
At the moment I use frames in my webpages (e.g.
www.smorf.nl/frames360.html), I didn't want to have to reload the
applet all the time. Since I don't like frames, I'm rebuilding my
website without them. This is going quite well, the only downside is
that users will have to load new pages, and so do a applet reload, now
and then. Not much of a problem really, but unfortunately, in Firefox,
doing a couple of quick reloads crashes the applet, I get an error
like:
"Exception in thread "Thread-2252" java.lang.OutOfMemoryError: Java
heap space".

This is the output (edited) of the java console:
------------------------------------------------
Java Plug-in 1.5.0_03
Using JRE version 1.5.0_03 Java HotSpot(TM) Client VM

Smorf 2.11.06 17-11-2005
Smorf 2.11.06 17-11-2005
Smorf 2.11.06 17-11-2005
Smorf 2.11.06 17-11-2005
Cookie service is not available - use cache to determine "Cookie"
Smorf 2.11.06 17-11-2005
Smorf 2.11.06 17-11-2005
Cookie service is not available - use cache to determine "Cookie"
Smorf 2.11.06 17-11-2005
Smorf 2.11.06 17-11-2005
Smorf 2.11.06 17-11-2005
Smorf 2.11.06 17-11-2005
Exception in thread "Thread-2252" java.lang.OutOfMemoryError: Java
heap space
------------------------------------------------
Every time the applet loads, it writes the string "Smorf 2.11.06
17-11-2005" to the console. What the cookie messages are doing here, i
can't understand. I don't do anything with cookies.
I tried this in IE (with Microsoft's VM), no crashes, although the
applet performance definitely decreases
In Opera 8.5 also get a OutOfMemoryError after about 20 reloads.
Before that happens, I get null pointer exceptions. Other than that
the applet seems to work fine, of course until it crashes on the
OutOfMemoryError.
I have never had this problem in the frames version.
If my own code is the problem I don't know how to solve it. Java has
automatic garbage collection, right?
If you could help me find out what the problem/solution could be, that
would be great.

thanks, Mark.

My system:

Windows 2000 SP4, IE 6.0 with SP1 and the MS JVM, Opera 8.5, Firefox
1.5.
 
M

Michael Redlich

Hi, Mark:
Hi all,

I have this java applet that shows 3D objects in a browser. The applet
interacts with javascript, users can choose objects for viewing by
clicking on a hyperlink.
At the moment I use frames in my webpages (e.g.
www.smorf.nl/frames360.html), I didn't want to have to reload the
applet all the time.

Very nice web site! I'm a polymer physicist/computer scientist (long
story) so I really enjoyed viewing the different crystals.
Since I don't like frames, I'm rebuilding my
website without them. This is going quite well, the only downside is
that users will have to load new pages, and so do a applet reload, now
and then. Not much of a problem really, but unfortunately, in Firefox,
doing a couple of quick reloads crashes the applet.
Every time the applet loads, it writes the string "Smorf 2.11.06
17-11-2005" to the console. What the cookie messages are doing here, i
can't understand. I don't do anything with cookies.
I tried this in IE (with Microsoft's VM), no crashes, although the
applet performance definitely decreases
In Opera 8.5 also get a OutOfMemoryError after about 20 reloads.
Before that happens, I get null pointer exceptions. Other than that
the applet seems to work fine, of course until it crashes on the
OutOfMemoryError.
I have never had this problem in the frames version.

I'm not 100% sure, but it almost seems as if each frame has it's own
memory space which may explain why nothing crashes using frames. If
someone can confirm this theory, I would certainly appreciate it...
If my own code is the problem I don't know how to solve it. Java has
automatic garbage collection, right?

Yes, but the JVM invokes the garbage collector when it feels like doing
so. Even an explicit call to System.gc() doesn't guarantee that the
garbage collector is invoked immediately.
If you could help me find out what the problem/solution could be, that
would be great.

If you don't want to use frames, have you given some consideration to
using AJAX? I am in the early stages of learning this relatively new
technology, but the idea is to make asynchronous calls to the web
server to update only portions of a loaded web page without having to
fully reload it.

It's just a thought that may help, but since I don't have any real
experience with it yet, I can't say for sure at this point.

Here's where the experieced AJAX developers out there can chime in!

Sincerely,

Mike.
 
T

Thomas Hawtin

Mark said:
and then. Not much of a problem really, but unfortunately, in Firefox,
doing a couple of quick reloads crashes the applet, I get an error
like:
"Exception in thread "Thread-2252" java.lang.OutOfMemoryError: Java
heap space".

It's difficult to see what's going on without the source. If it is only
quick reloads, perhaps you are not exiting the applet quick enough,
giving lots of applets running simultaneously during the 20 second grace
period. Perhaps you are storing data in a static variable and never
letting go of it.

Thread-2252? That's an awful lot of threads you seem to be creating there.

Running it under the 1.5.0_06 appletviewer (on Fedora Core 4), I get a
sky image followed by high CPU usage and the applet not redrawing.

Tom Hawtin
 
M

Mark

Hi Mike,

Thanks, I'm glad you enjoyed it :)
You might be right about the frames, I tried to let the frames page
crash by reloading it lots of times but I couldn't.
Regarding AJAX, I am experimenting with that, seems to be working
very well. It might solve my problem for my own website but then my
applet is used by other people and their website has the same
problem..

regards, MArk.
 
M

Mark

Hi Tom,

Thanks for your answer. I don't have data in static variables. Also I
checked the java console to see if I had more than one applet running,
but appearantly this is not the case and I always get all the
Destroying applet, Disposing applet, Quiting applet messages when I
reload the page.

Also i checked the thread list and thread stack in the java console,
I'm not sure I'm interpreting things right, but if I count all the
threads, their number remains more or less the same, about 20 threads.
I see the same number of threads in the Windows task manager.

But for example this entry in the thread stack, could it be that my
applet.run method keeps generating threads?
----------------------------
Full thread dump Java HotSpot(TM) Client VM (1.5.0_03-b07 mixed mode,
sharing):

"Thread-1996" prio=4 tid=0x02b239a0 nid=0x220 runnable
[0x068bf000..0x068bfbe4]
at SmorfApplet.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

----------------------------

If you run the applet in the appletviewer you'll just see a blue sky,
that's right. You would have to invoke the leesfile(String naam)
method to display a crystal..
The high CPU usage is because I have a loop in the applet.run method
to keep the applet running.. I don't know how to keep the CPU usage
down when there's no crystal displayed or the user isn't doing
anything (like rotating the crystal, or loading a new ine etc.)

regards. Mark.



y On Thu, 29 Dec 2005 12:07:23 +0000, Thomas Hawtin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top