Applets and memory not being released by Java Plug-in

Hi.
I am experiencing a strange memory-management behavior of the Java Plug-in with Java Applets. The Java Plug-in seems not to release memory allocated for non-static member variables of the applet-derived class upon destroy() of the applet itself.
I have built a simple "TestMemory" applet, which allocates a 55-megabytes byte array upon init(). The byte array is a non-static member of the applet-derived class. With the standard Java Plug In configuration (64 MB of max JVM heap space), this applet executes correctly the first time, but it throws an OutOfMemoryException when pressing the "Reload / Refresh" browser button or if pressing the "Back" and then the "Forward" browser buttons. In my opionion, this is not an expected behavior. When the applet is destroyed, the non-static byte array member should be automatically invalidated and recollected. Isn't it?
Here is the complete applet code:
// ===================================================
import java.awt.*;
import javax.swing.*;
public class TestMemory extends JApplet
  private JLabel label = null;
  private byte[] testArray = null;
  // Construct the applet
  public TestMemory()
  // Initialize the applet
  public void init()
    try
      // Initialize the applet's GUI
      guiInit();
      // Instantiate a 55 MB array
      // WARNING: with the standard Java Plug-in configuration (i.e., 64 MB of
      // max JVM heap space) the following line of code runs fine the FIRST time the
      // applet is executed. Then, if I press the "Back" button on the web browser,
      // then press "Forward", an OutOfMemoryException is thrown. The same result
      // is obtained by pressing the "Reload / Refresh" browser button.
      // NOTE: the OutOfMemoryException is not thrown if I add "testArray = null;"
      // to the destroy() applet method.
      testArray = new byte[55 * 1024 * 1024];
      // Do something on the array...
      for (int i = 0; i < testArray.length; i++)
        testArray[i] = 1;
      System.out.println("Test Array Initialized!");
    catch (Exception e)
      e.printStackTrace();
  // Component initialization
  private void guiInit() throws Exception
    setSize(new Dimension(400, 300));
    getContentPane().setLayout(new BorderLayout());
    label = new JLabel("Test Memory Applet");
    getContentPane().add(label, BorderLayout.CENTER);
  // Start the applet
  public void start()
    // Do nothing
  // Stop the applet
  public void stop()
    // Do nothing
  // Destroy the applet
  public void destroy()
    // If the line below is uncommented, the OutOfMemoryException is NOT thrown
    // testArray = null;
  //Get Applet information
  public String getAppletInfo()
    return "Test Memory Applet";
// ===================================================Everything works fine if I set the byte array to "null" upon destroy(), but does this mean that I have to manually set to null all applet's member variables upon destroy()? I believe this should not be a requirement for non-static members...
I am able to reproduce this problem on the following PC configurations:
* Windows XP, both JRE v1.6.0 and JRE v1.5.0_11, both with MSIE and with Firefox
* Linux (Sun Java Desktop), JRE v1.6.0, Mozilla browser
* Mac OS X v10.4, JRE v1.5.0_06, Safari browser
Your comments would be really appreciated.
Thank you in advance for your feedback.
Regards,
Marco.

Hi Marco,
my guess as to why JPI would keep references around, if it does keep them, is that it propably is an implementation side effect. A lot of things are cached in the name of performance and it is easy to leave things laying around in your cache. Maybe the page with the associated images/applets is kept in the browser cache untill the browser needs some memory and if the browser memory manager is not co-operating with the JPI/JVM memory manager the browser is not out of memory, thus not releasing its caches but the JVM may be out of memory. Thus the browser indirectly keeps the reference that it realy does not need. This reference could be inderect through some 'applet context' or what ever the browser uses to interact with JPI, don't realy know any of these details, just imaging what must/could be going on there. Browser are amazingly complicated beast.
This behaviour that you are observing, weather the origin is something like I speculated or not, is not nice but I would not expect it to be fixed even if you filed a bug report. I guess we are left with relleasing all significatn memory structures in destroy. A simple way to code this is not to store anything in the member fields of the applet but in a separate class; then one has to do is to null that one reference from the applet to that class in the destroy method and everything will be relased when necessary. This way it is not easy to forget to release things.
Hey, here is a simple, imaginary, way in which the browser could cause this problem:
The browser, of course needs a reference to the applet, call it m_Applet here. Presume the following helper function:
Applet instantiateAndInit(Class appletClass) {
Applet applet=appletClass.newInstance();
applet.init();
return applet;
When the browser sees the applet tag it instantiates and inits the new applet as follows:
m_Applet=instantiateAndInit(appletClass);
As you can readily see, the second time the instantiation occurs, the m_Applet holds the reference to the old applet until after the new instance is created and initlized. This would not cause a memory leak but would require that twice the memory needed by the applet would be required to prevent OutOfMemory.I guess it is not fair to call this sort of thing a bug but it is questionable design.In real life this is propably not this blatant, but could happen You could try, if you like, by allocating less than 32 Megs in your init. If you then do not run out of memory it is an indication that there are at most two instances of your applet around and thus it could well be someting like I've speculated here.
br Kusti

Similar Messages

  • My ipod touch 4g is not charging using a wall charger and is not being recognize whatsoever by my laptop (windows) any help?, My ipod touch 4g is not charging using a wall charger and is not being recognize whatsoever by my laptop (windows) any help?

    My ipod touch 4g is not charging using a wall charger and is not being recognize whatsoever by my laptop (windows) any help?, My ipod touch 4g is not charging using a wall charger and is not being recognize whatsoever by my laptop (windows) any help?

    Hvae you tried here:
    iOS: Device not recognized in iTunes for Windows
    iPod touch: Hardware troubleshooting
    Have you tried another cable?
    Look at the dock connector. Look for abnormalities like bent or corroded contacts, foreign material and cracked or broken plastic

  • After updating ios my ipad is stuck in recovery mode and is not being recognised by the computer in windows or itunes.  Help!

    Help - I am stuck in Afghanistan on operations and my iPad mini has died.
    I tried to update the IOS as directed, there were a few error messages and I cancelled the process.
    The ipad now only shows the connect to itunes screen and is not being recognised by the computer in either windows or itunes.
    I have tried several resets and restarted the computer and reinstalled itunes.
    Is there anything else I can do.
    This is my only method of talking back to my family at the moment and is really quite important.
    JS

    Thanks, I will give it a go. Will it work on my computer after I do that?
    Jez

  • HT4061 my iPhone unexpectedly shut down and now is not turning back on, charging and is not being detected by my laptop, help

    my iPhone unexpectedly shut down and now is not turning back on, charging and is not being detected by my laptop, help

    i put that i held down the home button and all that... sorry, should of made my message a little clearer hun.. but i did try that, ive been searching video's on the net trying to figure out how to fix the problem, but nothing seems to be working... ive just tried pluging the usb lead into my phone while holding the home button then connecting it to my computer to see if itunes fires up, but even that didnt work... i dont know what else to try.

  • My ipod nano 5th gen. wont turn on and is not being recognized on my mac or itunes

    my ipod nano 5th gen. wont turn on and is not being recognized on my mac or itunes

    What have you tried so far in terms of troubleshooting?  After leaving the Nano to sit and charge for at least 30 minutes, try resetting it by pressing and holding both the Select/Center and Menu buttons together long enough for the Apple logo to appear. You'll want to make sure the Hold Switch is not in the On position as well.
    B-rock

  • My iphone 5 is disabled and is not being read by itunes, itunes is giving me a prompt of my passcode, but that screen is not showing, please help me able my iphone.

    my iphone 5 is disabled and is not being read by itunes, itunes is giving me a prompt of my passcode, but that screen is not showing, please help me able my iphone.

    +Do a DFU recovery:+
    +1. Open iTunes.+
    +2. Connect the iPhone+
    +3 Press both the home and sleep/wake buttons until the Apple icon appears (ignore the red slider if it shows).+
    +4. Continue pressing the home button alone until iTunes sees your phone in recovery mode.+
    +5. Follow the prompts to restore the iPhone.+
    If not, take it down to mobile dealers that can reset your phone for you. All data will be lost.

  • I can't save a thing, and memory is being stolen? I want to try free "virus scan" app from apple, tho cannot

    Can u help me?

    I can't save a thing, and memory is being stolen? I want to try free "virus scan" app from apple, tho cannot
    Following BookmarkShow 0 Bookmarks Actions

  • IPod Touch will not power up and will not respond to itunes when plugged into a computer

    iPod Touch will not power up and will not respond to itunes when plugged to computer, have tried holding both buttons down for 10 secs like support suggest but nothing has happen. Any suggestions?

    Try the other actions here:
    iOS: Not responding or does not turn on

  • Will Installing more RAM improve performanc​e, IF laptop has "available memory" not being used?

    My laptop has 2x 1GB of RAM.
    Right now, and usually, The Physical Memory shown in Task Manager, shows that there is "available memory" (currently it's 500megs worth). (And "system cache" says 300megs.)
    There is also, right now, 2.5GB of page filing being used.
    If I were to replace the 2GB of RAM with 4GB (of the same Mhz), would there be a noticable increase in performance?
    (windows XP 32bit OS)

    A matched set of DDR2 ram will perform a lot faster one memory not matched. Its required for the double data rate to work. Hence 2+2 is the max you'd need/want in a 32bit machine. Windows 7 was built for large memory footprints. XP was built to run just barely in 64MB but really needed a min of 128MB to support a network connection and printing. It was never enable to truely go a whole lot further than a few machines built capable of 1GB. There was even a bug which was patch causing problems if a !GB or more was available. Just because it can see it does not mean it actually uses it !! The kernal by default is swapped in/out of ram even in larger memory systems. Why, it was is not aware of the extra memory and does not change its behavour from a 512MB machine.
    As for the 1333Mhz ram the timing may be faster than the other memory used. Hence it flow the data faster on the bus. Fewer delays in various cycles including the RAS/CAS etc but thats all under the hood so to speak.
    T520 Model 4239 Intel(R) Core(TM) i7-2860QM CPU @ 2.50GHz
    Intel Sandy Bridge & Nvidia NVS 4200M graphics Intel N 6300 Wi-Fi adapter
    Windows 7 Home Prem - 64bit w/8GB DDR3

  • StorEdge 3310 Slowness and "Memory Not Sufficient" Error

    Hello,
    I have a 3310 single-controller array who's LUN inexplicably became incredibly lethargic a couple of days ago. I checked the controller's event log and have the following message: "Controller WARNING: memory not sufficient to fully support current configuration". And it takes several minutes to perform any inquiry within sccli.
    I found a Sun Doc 201253 that referenced Bug ID 6382051 for the 3510 with pre-4.21 firmware, but nothing that spoke of the 3310. I even followed the instructions from that Doc and disabled FTP, but nothing changed. The 3310's firmware is completely up to date (done last summer). This is on a high-usage system so we're still discussing the scheduling for a controller reset (to clarify -- NO reset/reboot has been attempted yet), but I wanted to see if anyone has any ideas or has seen this before? Thanks!
    - Dion

    Start at the beginning..
    At the obp prompt do you see the array and all disks via a probe-scsi-all?
    If yes, then the hardware would appear to be ok.
    At the OS, are the additional logical devices being created review via devsfadm -c disks; devfsadm -al
    Is the qus driver loaded, via modinfo
    Is the qus patch loaded via showrev -p |grep patchid
    Does the scsi loop, ie. cable lenght comply with SCSi loop rules > less than 10m I think
    Is it JBOD array or do you have raid controllers, if raid controllers have you physically configured the Luns on the array?
    Is it a single loop configuration, if so have you got the loop cable to connect one half of the array to the other?
    If the answer is yes to all then format should be correct.

  • Copy/Paste worked in JDK 1.4 and does not work more for Java 1.4.1_01

    Hi all,
    in JDK 1.4.0 we can use the copy/paste between the java applets and other windows applications but in JDK 1.4.1_01 it does not work more!!!
    there is a simple JApplet code:
    import java.awt.*;
    import javax.swing.*;
    public class JApplet1 extends JApplet
         public void init()
              getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
              getContentPane().setLayout(null);
              setSize(426,266);
              getContentPane().add(JTextField1);
              JTextField1.setBounds(72,72,283,64);
         javax.swing.JTextField JTextField1 = new javax.swing.JTextField();
    and the start html page the the Japplet
    <HTML>
    <HEAD>
    <TITLE>Autogenerated HTML</TITLE>
    </HEAD>
    <BODY>
    <OBJECT classid="clsid:CAFEEFAC-0014-0001-0000-ABCDEFFEDCBA"
    width="500" height="200" >
    <PARAM name="code" value="JApplet1.class">
    <PARAM name="codebase" value=".">
    <PARAM name="type" value="application/x-java-applet;jpi-version=1.4.1">
    <PARAM name="scriptable" value="true">
    No Java 2 SDK, Standard Edition v 1.4.1 support for APPLET!!
    </OBJECT>
    </BODY>
    </HTML>
    Any ideas?
    Best regards

    Hi,
    I have found out the cause for the issue: before you install 1.4.1_01.exe you must deinstall all JRE's on your computer (1.3.XX, 1.4.0.XX) than works that well the Copy/Paste.
    that is confusingly because we don't have to make that in JRE 1.4.0.
    Best regards

  • IPod is not playing songs and is not being recognised by Windows AT ALL.

    Whenever I turn it on, the error flashes and I can't play songs. When I connect it to a computer, a flashing orange light comes on to say it's charging and do not disconnect.
    It is not appearing in iTunes, My Computer. Device manager shows a 'storage device' and that it is located on an Apple iPod.
    I run the iPod installer that came on the disc, it recognises the iPod is there and says it needs to be formatted. I press format but then it says there was an error communicating with the iPod. There is nothing I can do about this.
    Is this happening to anyone else and what can I do? If you need more information, just ask. Tech support was no real use and I am becoming very frustrated.
      Windows XP Pro  

    Whenever I turn it on, the error flashes and I can't
    play songs. When I connect it to a computer, a
    flashing orange light comes on to say it's charging
    and do not disconnect.
    It is not appearing in iTunes, My Computer. Device
    manager shows a 'storage device' and that it is
    located on an Apple iPod.
    I run the iPod installer that came on the disc, it
    recognises the iPod is there and says it needs to be
    formatted. I press format but then it says there was
    an error communicating with the iPod. There is
    nothing I can do about this.
    Is this happening to anyone else and what can I do?
    If you need more information, just ask. Tech support
    was no real use and I am becoming very
    frustrated.
    Windows XP Pro  
    My Ipod is doing the same. How do I fix this?

  • My battery  wont charge and its not being recognized.

    Okay, I got my MacBook yesterday (4-7-08) and I noticed that it wasn't charging. Went through all the different ways of trying to fix it and have come to the conclusion that it is a bad battery. I called customer service today and all my spec. and what not are bad....like really bad....
    +AC Charger Information:+
    +Connected: Yes+
    +Charging: No+
    +Battery Information:+
    +Model Information:+
    +Device name: ASMB016+
    +Pack Lot Code: 0002+
    +PCB Lot Code: 0000+
    +Firmware Version: 0110+
    +Hardware Revision: 0500+
    +Cell Revision: 0102+
    +Charge Information:+
    +Charge remaining (mAh): 0+
    +Fully charged: No+
    +Charging: No+
    +Full charge capacity (mAh): 0+
    +Health Information:+
    +Cycle count: 0+
    +Battery Installed: No+
    +Amperage (mA): 0+
    +Voltage (mV): 0+
    Now, about 20 minutes ago, I notices that it's not even recognizing the battery at all. So, now I'm trying to figure it out.
    I received this laptop from school. I'm am a graphic design student and I have never really used a Mac before...I just want to know if it's just the battery or if I need a whole new one.
    Please help!?!?! What do I need to do? What the hecks is wrong with it??
    Message was edited by: xshesxpoisonx

    Try resetting the SMC.
    Unplug the computer. Remove the battery. Hold down the power button for *5 seconds.* Put the battery back in. Plug the computer back in and turn it on.
    Unfortunately technology is not perfect and you may have received a dud. But that's a load of crap that the school won't take it back. Did you get it at your school's computer store, or is it used and they gave them away? If you got it from the store, then there's no reason why they shouldn't take it back. Ask to speak to a manager.

  • On my ipad3, the Skype IM is not running. All msgs i send are shown as "pending" and are not being sent out.

    On my ipad3 skype IM is not running. The msgs are shown as "pending" and are not going out.
    Also i could earlier send sms to mobiles from skype. Now that facility has dissapeared from teh menu.
    Very thankful for any help.

    You both backup your iPhones on the same Apple ID, so when she restore her iPhone it pulled the data from the last backup (your iPhone).  She would need to erase her iPhone and restore from her back up. Take a look at this link in the restore section, http://support.apple.com/kb/HT4859

  • Adobe 8.1.1 patch does not exsit, or the java plug in is not available

    I can not open any pdf files. the message I get is that the Java plug in is not there and when I try to update Java it screws up too. when I tried to uninstall adobe acrobat reader the messages I get is that the adobe patch is not there or to check with adobe to see if it is an actual update from them so I can not remove it to replace it again.

    Have you tried the Windows Installer CleanUp Utility at http://support.microsoft.com/kb/290301 ?
    Remove the problematic version, then install the newest one. B.t.w. there is no such thing as 8.2, at least not publicly available.

Maybe you are looking for

  • How can I import an project .imoviemobile file to imovie 10.0.6 on my mac book for further processing

    How can I import an project .imoviemobile file to imovie 10.0.6 on my mac book for further processing?

  • How to calculate the percentage of free space for a table in Oracle

    okay, I am a little confused here. I have been searching the web and looking at a lot of documents. What I basically want to find out is this, how do I calculate the difference between the number of bytes a table is using and the total bytes allocate

  • Uploading Printer fonts

    UPLOADING PRINTER FONTS Every printer manual I've looked at talks about downloading fonts to the printer. I understand that part; but can I upload the fonts to my ibook? If a printer is advertised as coming with, say, 136 Postscript fonts, will they

  • Port 4567 (backdoor)

    Hello, After a lot of digging around this forum i found i very useful post, it talked about a backdoor in the firmware. The thread is read only, it had been closed due to repetitive posts http://community.bt.com/t5/BB-in-Home/Why-have-BT-​put-a-backd

  • HP XW4300 F10 no respond

    Hello, I need to go into bios setup because i get error 101 an add-in card installed is not working correctly. This is a video card like a was intented to upgrade the original one, after I come to the old one again, but still the error on, at this ti