0

I have a situation where a Java Applet hangs after being opened multiple times. This only happens on systems with low RAM which leads me to believe there might be a memory leak, or just insufficient memory allocated to the heap.

How can I test an applet for memory leaks? Would something like JProbe work?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
R.V.
  • 532
  • 1
  • 6
  • 21
  • 1
    If you're using a recent edition of Java use VisualVM - it should already be part of the JDK. You can trace memory leaks etc. with it. – Adam Jun 20 '12 at 00:01
  • I followed your advice and used VisualVM... the problem is that the applet gives trouble after being closed and opened multiple times. So I am not sure how I can keep track of any resources it locks BETWEEN runs. – R.V. Jun 20 '12 at 00:27
  • Is your applet using some DLLs etc ? – Umer Hayat Jun 20 '12 at 03:50

1 Answers1

0

I don't think that low ram on a specific workstation is an issue.

If not specified otherwise (with -Xmx setting), Java applets get 64MB of memory at the start. The JVM reserves this amount of RAM from the system at the very beginning, so if the system has less memory available the JVM (and thus, the Applet) will not even start.

But if it starts, it's guaranteed to have all the configured memory available. So, if your Applet still lacks memory, there are two possibilities:

  1. The default setting (64MB) is to low - configure your applet to get more RAM.
  2. You are not releasing resources properly, and leaking memory. Take look at your applet's lifecycle methods, and check if you are releasing resources like you should.

Also, you say that in the end, your applet hangs. To see what is going on, add some loging to lifecycle methods, enable Java Console, and look for exceptions.

npe
  • 15,395
  • 1
  • 56
  • 55
  • Thanks. How can I accomplish (1)? – R.V. Jun 20 '12 at 17:46
  • See [here](http://stackoverflow.com/questions/5026376/applet-java-heap-space), [here](http://www.duckware.com/pmvr/howtoincreaseappletmemory.html) or [here](http://docs.oracle.com/javase/tutorial/deployment/deploymentInDepth/embeddingJNLPFileInWebPage.html) – npe Jun 20 '12 at 18:00
  • These solutions require modification of code. For now, this is something I would like to avoid. Would adding -Xmx and -Xms through the **Control Panel** work instead? – R.V. Jun 20 '12 at 20:12
  • Yes, using `-Xmx` setting in Java Control Panel is one of the options. – npe Jun 20 '12 at 21:16