Applet Memory Leak - Resizing Images

Hello,
I'm having an issue with a Java Applet I have written. The applet reads a directory listing, and displays resized thumbnails in a JTable. The problem is, if the user loads a directory with a lot of large images, the memory usage sky rockets, and is not freed after the user shuts down the applet.
Below is the code which adds the resized image to a custom table model:
    public void leftClick(){
         main.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        FileSystemView fsv = FileSystemView.getFileSystemView();
        ImageIcon thumbnailIcon = new ImageIcon();
        ImageIcon icon = new ImageIcon();
        File selectedFile = fileTree.getSelectedFile();
        Image scaledImage;
        if(selectedFile!=null){
            if (selectedFile.isDirectory()){
                File subFiles[] = selectedFile.listFiles();
                mvtm.clearList();
                fileTable.removeAll();
                TableColumn col = fileTable.getColumnModel().getColumn(0);
                col.setMaxWidth(35);
                col = fileTable.getColumnModel().getColumn(1);
                col.setPreferredWidth(200);
                col = fileTable.getColumnModel().getColumn(3);
                col.setPreferredWidth(0);
                col.setMaxWidth(0);          
                for(int i = 0;i<subFiles.length;i++){
                    if(subFiles.getName().toLowerCase().contains(".jpg")||
subFiles[i].getName().toLowerCase().contains(".gif")||
subFiles[i].getName().toLowerCase().contains(".png")||
subFiles[i].getName().toLowerCase().contains(".bmp")){
icon = new ImageIcon(subFiles[i].getPath());
scaledImage = Utils.getScaledImage(icon.getImage(), 30, 30);
thumbnailIcon = new ImageIcon(scaledImage);
}else{
icon = (ImageIcon)fsv.getSystemIcon(subFiles[i]);     
scaledImage = Utils.getScaledImage(icon.getImage(), 30, 30);
thumbnailIcon = new ImageIcon(scaledImage);
mvtm.addFileRecord(thumbnailIcon, subFiles[i].getName(),
Long.toString(subFiles[i].length()), subFiles[i]);
main.setCursor(null);
The resize method is here:
    static Image getScaledImage(Image srcImg, int w, int h){
        BufferedImage resizedImg;
        resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = resizedImg.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g2.drawImage(srcImg, 0, 0, w,h, Color.WHITE, null);
        g2.dispose();
        return resizedImg;
    }I have tried to nullify all objects created by overriding the applet destroy method:
    public void destroy(){
        fileTree.getFileTreeListener().clearMvtm();
        addButton = null;
        fileTable = null;
        jLabel1 = null;
        jPanel1 = null;
        jPanel2 = null;
        jProgressBar1 = null;
        jScrollPane1 = null;
        jScrollPane2 = null;
        jScrollPane3 = null;
        messageLabel = null;
        removeButton = null;
        uploadButton = null;
        uploadQueueTable = null;
        fileTree = null;
        fileModel = null;
        uploadQueueModel = null;
        task = null;
        Runtime r = Runtime.getRuntime();
        r.gc();
    }Any help is appreciated.
Ryan
Edited by: rthompson2000 on Sep 24, 2008 10:33 AM

Hi SoulTech,
thanks for the response. Interesting point I forgot to mention. On my machine, the JVM launches separately, (ie, I get the little Java icon in my task tray on the bottom right of my PC). When I close the applet pop-up, the java icon is still there, and the java.exe process is still running in Task Manager. After about a minute or two, the Java icon disappears, and Java.exe is no longer a running process (ie. the memory is gone, but this takes a minute or two! I want this to stop immediately).
When I try this in a friends PC, they don't get the JVM icon in their taskbar, and all of the memory is allocated to the ieexplorer.exe process. After they close the applet pop-up window, browsing is very slow since their IEexplorer memory is very high because of the applet.
can you hook up a profiler?
I'm just getting familiar with the Netbeans profiler. I am able to see that all of the memory is being allocated in the leftClick() method I posted above. All of the memory is being hogged mainly by type int[] in sun.awt.image.ImageRepresentation.setPixels() and java.awt.image.DataBufferInt
can you see the vm in the process table?
See my above explanation. The java.exe process seems to die after a minute or two, but I don't think it frees memory when the VM is running inside the browser (as in the case on my friends PC)
are you sure destroy is even getting called?
How can I be sure? You said it didn't need to have anything in it anyways so does it matter?
are you getting errors?
No errors.

Similar Messages

  • Memory leak in image rings on Linux

    Hello all,
    I have a very serious problem I didn't have in previous version of my soft and one of the only addition I've made recently is to use image rings. The soft uses 6Mb more every minute. If I remove the rings, it stops. It could be a wrong lead, so I'm trying to write a test case, but is there a list of identified memory leaks somewhere ?
    THanks.
    Solved!
    Go to Solution.

    OK guys, there's a very serious leak on Linux, confirmed by the code below. Every time you change the value of a picture ring, either by clicking on the arrow of the picture ring or right-click on it (callback to SetCtrlVal), it uses 1 extra Mb of mem for a 512x512 pixel image !!!
    Here's a sample code:
    // Right-click the ring to cause memory leak
    #include <stdio.h>
    #include <stdlib.h>
    #include <cvirte.h>
    #include <userint.h>
    #define RND_COLOR (((rand()<<16) ^ (rand()<<8) ^ rand()) & 0xFFFFFF)
    // (int)((double)(0xFFFFFF)*rand()/RAND_MAX)
    static int Pnl=0,
    Text, Ring, // Controls
    NbVals=16, // Number of images in the ring
    Width=512, Height=512; // Of the Canvas and image ring
    // Returns memory used by process in 4Kb page:
    // TotalSize Resident Share Text Lib Data Dirty
    // See "man proc" section statm
    static char* ReadOffMemoryStatus(void) {
    static char statm[80];
    statm[0]='\0';
    #ifdef _NI_linux_
    FILE *f = fopen("/proc/self/statm","r");
    if (f)
    fgets (statm, 79, f),
    fclose(f);
    #endif
    return statm;
    static void Prepare(const int Nb) {
    Point polyPoints[10]={{0,0}};
    char Str[10];
    int i, Bitmap;
    int Canvas=NewCtrl(Pnl, CTRL_CANVAS, "", 0, 0);
    SetCtrlAttribute(Pnl, Canvas, ATTR_DRAW_POLICY, VAL_UPDATE_IMMEDIATELY);
    SetCtrlAttribute(Pnl, Canvas, ATTR_WIDTH, Width);
    SetCtrlAttribute(Pnl, Canvas, ATTR_HEIGHT, Height);
    // SetCtrlAttribute(Pnl, Canvas, ATTR_ENABLE_ANTI_ALIASING, 1); // No compile on Linux
    SetCtrlAttribute(Pnl, Canvas, ATTR_PICT_BGCOLOR, RND_COLOR /*VAL_TRANSPARENT*/);
    SetCtrlAttribute(Pnl, Canvas, ATTR_PEN_FILL_COLOR, RND_COLOR);
    SetCtrlAttribute(Pnl, Canvas, ATTR_PEN_COLOR, RND_COLOR);
    SetCtrlAttribute(Pnl, Canvas, ATTR_PEN_WIDTH, 7);
    for (i=0; i<10; i++)
    polyPoints[i].x=(Width*rand()/RAND_MAX),
    polyPoints[i].y=(Height*rand()/RAND_MAX);
    sprintf(Str, "%d", Nb);
    // CanvasStartBatchDraw(Pnl, Canvas);
    // This sometimes doesn't work on Linux
    CanvasDrawPoly (Pnl, Canvas, 10, polyPoints, 1, VAL_DRAW_FRAME_AND_INTERIOR);
    CanvasDrawLine (Pnl, Canvas, MakePoint(Width-1,0), MakePoint(0, Height-1));
    SetCtrlAttribute(Pnl, Canvas, ATTR_PEN_COLOR, VAL_BLACK);
    SetCtrlAttribute(Pnl, Canvas, ATTR_PEN_FILL_COLOR, VAL_WHITE);
    CanvasDrawText(Pnl, Canvas, Str, VAL_APP_META_FONT,
    MakeRect (2, 2, VAL_KEEP_SAME_SIZE, VAL_KEEP_SAME_SIZE), VAL_UPPER_LEFT);
    // CanvasEndBatchDraw(Pnl, Canvas);
    GetCtrlBitmap(Pnl, Canvas, 0, &Bitmap);
    DiscardCtrl (Pnl, Canvas);
    InsertListItem(Pnl, Ring, Nb, NULL, Nb); // The value is the color, so remember which one you use
    SetCtrlBitmap (Pnl, Ring, Nb, Bitmap);
    DiscardBitmap (Bitmap);
    int CVICALLBACK cb_Change(int panel, int control, int event,
    void *callbackData, int eventData1, int eventData2) {
    static int i=0;
    switch (event) {
    case EVENT_RIGHT_CLICK:
    case EVENT_RIGHT_DOUBLE_CLICK:
    SetCtrlVal(Pnl, Ring, i=(i+1)%NbVals);
    // No break;
    case EVENT_COMMIT:
    SetCtrlVal(Pnl, Text, ReadOffMemoryStatus());
    break;
    return 0;
    int CVICALLBACK cb_Quit(int panel, int control, int event,
    void *callbackData, int eventData1, int eventData2) {
    switch (event) {
    case EVENT_COMMIT: QuitUserInterface (0); break;
    return 0;
    int main (int argc, char *argv[]) {
    int i, Quit;
    if (InitCVIRTE (0, argv, 0) == 0) return -1;
    Pnl = NewPanel (0, "Test image ring", 20, 20, Height+20, Width);
    Text = NewCtrl (Pnl, CTRL_STRING_LS, "Memory use (in 4Kb pages)", 0, 0);
    Ring = NewCtrl (Pnl, CTRL_PICTURE_RING, "", 20, 0);
    Quit = NewCtrl (Pnl, CTRL_SQUARE_BUTTON_LS, "", 50, 50);
    SetCtrlAttribute(Pnl, Ring, ATTR_HEIGHT, Height);
    SetCtrlAttribute(Pnl, Ring, ATTR_WIDTH, Width);
    SetCtrlAttribute (Pnl, Ring, ATTR_CTRL_MODE, VAL_HOT);
    SetCtrlAttribute(Pnl, Ring, ATTR_CALLBACK_FUNCTION_POINTER, cb_Change);
    for (i=0; i<NbVals; i++) Prepare(i);
    SetCtrlAttribute(Pnl, Text, ATTR_WIDTH, 250);
    SetCtrlAttribute(Pnl, Text, ATTR_LABEL_LEFT, 250);
    SetCtrlAttribute(Pnl, Text, ATTR_LABEL_TOP, 0);
    SetCtrlAttribute(Pnl, Quit, ATTR_CALLBACK_FUNCTION_POINTER, cb_Quit);
    SetCtrlAttribute(Pnl, Quit, ATTR_VISIBLE, 0);
    SetCtrlAttribute(Pnl, Quit, ATTR_SHORTCUT_KEY, VAL_ESC_VKEY);
    SetPanelAttribute(Pnl, ATTR_CLOSE_CTRL, Quit);
    DisplayPanel (Pnl);
    RunUserInterface ();
    return 0;
    There are other issues as well:
     - CanvasDrawPoly sometimes doesn't work.
     - The anti-aliasing on a canvas doesn't compile.
    Is there anything more recent than CVI 2010 for Linux ?!?

  • Applet memory leak in IE 6.0?

    Hi :
    I am using the following tag to declare an applet, but when I load the page in IE each time I refresh the page, IE memory goes up by ~10MB!! And finally after 5-6 refreshes Microsoft's cunning browser crashes :-)). Any clues?
    -Sanjay.
    <OBJECT classid="com.hexidec.ekit.EkitApplet.class" NAME="Ekit" WIDTH="600" HEIGHT="400"></XMP>
         <PARAM NAME="code" VALUE="com.hexidec.ekit.EkitApplet.class">
         <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
         <PARAM NAME="scriptable" VALUE="true">
         <PARAM NAME="DOCUMENT" VALUE="Welcome to the rich text document editor.">
         <PARAM NAME="STYLESHEET" VALUE="ekit.css">
         <PARAM NAME="LANGCODE" VALUE="en">
         <PARAM NAME="LANGCOUNTRY" VALUE="US">
         <PARAM NAME="TOOLBAR" VALUE="true">
         <PARAM NAME="SOURCEVIEW" VALUE="false">
         <PARAM NAME="EXCLUSIVE" VALUE="true">
         <PARAM NAME="MENUICONS" VALUE="true">
         <PARAM NAME="archive" VALUE="eKit.jar">
         <PARAM NAME="cache_option" VALUE="Plugin">
         <PARAM NAME="cache_archive" VALUE="eKit.jar"></OBJECT>

    Hello Sanjaya,
    I am facing a very similar problem and my project is in danger - I was wondering if you have found a way to deal with that memory leak?
    Please let me know.
    Thanks.
    Tal

  • Applet memory leak

    It looks like that with Safari, when Javascript calls an applet function with a parameter, twice the size of the parameter is eated in memory and never released.
    This is a big problem in my HTML page since I send the content of a file so after 3 or 4 calls the function does not have anought memory anymore and produce strange behaviour.
    I use Safari 5.1.7 but the same code works fine with Chrome.
    regards

    OK, solved this by isolating the statement that caused the OutOfMemory error, then adding five, count 'em, five System.gc()'s just prior to the statement. I outputted the free memory after each gc and could see it increase each time.
    The statement in question was instantiating an extension of JViewPort which contained a JLayeredPane, the base layer of which is a pretty large image, but there are other populated layers as well. I'm no expert here, but it seems like a flaw, dare I say even a bug, in the garbage collector that it didn't handle this automatically.

  • Applescript Image Events appears to have memory leak (or I don't know what I am doing)

    Using Image Events to create images and thumbnails for a website. The following code results in very large memory leaks in Image Event process. I have documented results of test runs in the comments.
    The leak (or poor coding on my part) results in a total system halt if I attempt to process more than about 400 images at a time. Basically, I run out ot physical memory. I am running a new model 13" MBP with 8GM RAM.  I have to manually stop Image Events to reclaim the memory (or reboot of course).
    Any help/suggestions would be appreciated.
    (* test memory leak in Image Events *)
              tests with 58 photos selected in iPhoto
              5.7 MB left in Image Events after run with only open and close
              22.0 MB left in Image Events after run with open, save and close
              45.9 MB left in Image Events after run with open, scale, save and close
              A run with 382 photos selected used OVER 3.8 GB (gigabytes) and the
              mac ran out of physical memory so I had to stop the test.
    tell application "Finder"
              set imageFolder to folder "test" of home as alias
    end tell
    tell application "iPhoto"
              set currPhotoList to the selection
              repeat with currPhoto in currPhotoList
                        log name of currPhoto as string
                        set theImagePath to image path of currPhoto
                        tell application "Image Events"
      launch
                                  set theImage to open theImagePath
      scale theImage to size 128
      save theImage in imageFolder as JPEG with icon
      close theImage
                        end tell
              end repeat
    end tell
    --- end of code example

    Does the following code do any difference? Most likely no I guess… but better try than nothing.
    tell application "Finder"
        set imageFolder to folder "test" of home as text -- instead of “as alias” (see theTargetPath below)
    end tell
    set theImagePaths to {}
    set theImagePathsRef to a reference to theImagePaths -- faster with big lists
    tell application "iPhoto"
        set currPhotoList to the selection
        repeat with currPhoto in currPhotoList
            log name of currPhoto as string
            get POSIX file (image path of currPhoto) as alias -- faster ?
            copy result to the end of theImagePathsRef
        end repeat
    end tell
    tell application "Image Events"
        launch
        repeat with theImagePath in theImagePaths
            set theImage to open theImagePath
            scale theImage to size 128
            set theTargetPath to (imageFolder & name of theImagePath)
            save theImage in theTargetPath as JPEG with icon
            close theImage
        end repeat
    end tell

  • Memory leak with 1.6.0_07 in applet using Swing

    Java Plug-in 1.6.0_07
    Using JRE version 1.6.0_07 Java HotSpot(TM) Client VM
    Windows XP - SP2
    I have a commercial application that has developed a memory leak with the introduction of the latest plugin. The applets chew up memory and eventually freeze. They did not before. Using jvisualm I see a build up of native arrays, primarily int[][] and char[]. I'm still investigating. Anyone have a similar experience?
    The Applet uses a swing interface, uses buffered images and swing timers, and regularly performs http connections to the server which result in actions via the SwingUtil.invokeLater() method.

    I am Using Internet Explorer Browser Version 6.0.Huge security hole.
    Its not throwing Error / Exception Wrap a try/catch at the highest level possible.
    Catch 'Throwable'. And log/display it somewhere.

  • Memory Leak in edited images?

    I am using Captivate 4.0.1 Build 1658 (this means that the patch from May 2009 is applied) on Windows Vista.
    The following has happened to myself and at least 2 other developers.
    We edit a slide background image in Photoshop...when the  movie plays, a flash of the previously unedited background shows.  I have tried re-editing the background and it does not fix the problem. I have tried eliminating transistions and it does not fix the problem.  I have noticed that this happens when background images are edited in Photoshop as well as within Captivate when bitmaps are pasted onto a slide background and then merged into the background.
    I don't know if the correct term for this is a memory leak, but the closest mention of this problem I could find was here: http://blogs.adobe.com/captivate/2009/05/captvate_4_patch_update.html
    I appreciate any help resolving this.
    Thank you,
    Beth

    The Reset Firefox feature can fix many issues by restoring Firefox to its factory default state while saving your essential information.
    Note: ''This will cause you to lose any Extensions, Open websites, and some Preferences.''
    To Reset Firefox do the following:
    #Go to Firefox > Help > Troubleshooting Information.
    #Click the "Reset Firefox" button.
    #Firefox will close and reset. After Firefox is done, it will show a window with the information that is imported. Click Finish.
    #Firefox will open with all factory defaults applied.
    Further information can be found in the [[Reset Firefox – easily fix most problems]] article.
    Did this fix your problems? Please report back to us!

  • Image Memory Leaks in AIR app

    We are implementing an AIR application that loads thumbnails
    from the hard drive and uploads them to a remote server.
    When bringing in large images, for example, when importing
    five 2MB files into Image objects:
    Flex reports that it is using 55MB
    Windows reports using 220 Meg (viewing memory usage of
    adl.exe in task manager)
    After deletion of these image objects, the memory stays
    allocated!! It is released when the application is closed.
    Two issues I see:
    1. Huge memory usage for image objects (I understand that JPG
    files are exploded into BMPs). It limits our ability to load 10's
    or 100's of images.
    2. Bad Memory leak
    OTHER THINGS WE TRIED:
    1. Displaying images as inline html IMG tags.. Same memory
    usage!
    2. Taking a snapshot of the image and displaying that.
    Problem, used way to much CPU
    I hope these issues will be fixed before release time or we
    are hosed.
    PLATFORM: Windows XP Professional, service pack 2

    Hi
    Have you tried the FB3 profiler to investigate why memory is
    not getting deallocated?
    You can use the loitering objects panel to track the back
    references for the objects in memory. If you find that image object
    is not being referenced by anything else. Can you file a bug at
    http://bugs.adobe.com/flex
    with a small test case.
    Also as you know that jpg will be translated into bitmap. The
    amount of memory required will be determined by the pixels in the
    image. Each pixel will be 4K
    Thanks,
    Gaurav Jain
    Flex SDK Team

  • Memory Leak in Sun's Demo Applets

    After banging my head over some memory leak errors in an applet I wrote, I decided to try out one of Sun's applets to see if it too leaks memory. I loaded \j2sdk1.4.2_03\demo\applets\Animator\example1.html in IE6 (WinXP, JRE 1.4.2_03) and just left it running with the focus. At 11:45am the task manager showed IE to be using 13,100KB and over the past hour and a half that amount steadily increased to 16,424KB and keeps rising (now it's 16,452KB.) The problem I've run into in my applet (which does a lot of painting like this demo applet) is that it eventually just consumes more and more memory until it locks up.
    So I was wondering what advice people have. I've used JProfiler and I can't find any leaks in my code. I'm debating on making my applet a java application, but I'm just not sure if it will suffer from the same memory leaks. Thanks for any help.

    Well off hand with out seeing any code, check that you are not instantiating any object repeatedly...
    (creating new objects over and over and never getting rid of the old ones by still keeping referenced to it)
    something like this...
    public class MemoryEater
       MemoryEater()
          MemoryEater eater = new MemoryEater();
    public void doSomeThing()
       MemoryEater eater = new MemoryEater();
       eater.doSomeThing();
    }now this is a exaggerated example, but it might help you locate your memory leak...
    and memory usage varies depending on application and OS states... 1mb is not much of a rise, but then again overtime it makes a difference... Try other applets and see if you get the same results... I am currently running the same applet, and for a short bit the usage steadily climbed maybe about 2mb overall but then started to level off...
    Running the same applet, I got the initial memory usage increase,
    then a slow steady climb for about another meg and now it fluctuates between 36.5 and 37.5 mb...
    Note: I also have other Internet Explorer windows open, so naturally my overall memory usage is going to be higher...
    If it is still a problem, you can try re-installing the JVM...
    I hope this was helpful...
    - MaxxDmg...
    - ' He who never sleeps... '

  • Memory Leak in Applet

    Hello Good people,
    I am facing a troubling memory problem in my applet.
    Apparently, it suffers from some major memory leaks and every time I reload my applet the memory is consumed with additional 5Mb. I am looking for ways to work around this (or better yet to completely solve it) - I've noticed that the JVM is still alive when the applet is disposed and destroyed, it is not being killed until I close the parent IE windows. Because of this, the heap of the JVM is never totally cleaned and after several applet invocations I get to the heap's limit and everything is stuck.
    I am looking for ways to control the JVM - is there a way to manually reset its memory or even kill it through javascript after the applet is disposed?
    Thanks a lot!
    Tal

    Hi Andrew,
    I appreciate your help but I remember that in the research I did when I just started the project I have found that the web start technology is not suitable to me because it always open a new window and I need my applet to be embeded in an exisitng window.
    Do you know differently?
    Thanks,
    Tal

  • Memory Leak Java Plugin with Swing Applet

    Hi
    I experience the following problem and desperately need help on this. The Java Plugin (I use Version 1.3.1_02) seems to have a problem in printing Swing Applets.
    The problem can easily be reproduced (at least with NT):
    1) Start Internet Explorer or Netscape (I used 5.5/4.07)
    2) Launch the following demo swing applet
    http://java.sun.com/products/plugin/1.3.1_01a/demos/jfc/SwingSet2/SwingSet2Plugin.html
    3) Print the applet and observe (using task manager) the memory used by the browser process (the memory used by the process will increase every time you hit the print button but never decrease unless you shut down the browser)
    4) Print a couple of times (you may want to pause your print queue) and you will be able to crash your computer
    This seems to be the same bug reported with 4638742. However it says "in progress" for quite some time and I was wondering if some genious might know a work around for this.
    Cheers

    You might want to read an article about memory leaks in Java:
    http://www-106.ibm.com/developerworks/library/j-leaks/

  • Memory leak on applets

    I have a problem with a applet. My applet produces a memory leak with the plugging 1.5.0_08 and i can't fix it. With 1.5.0_07 plugging or older i don't have this problem. But the problem is not only in my applet, i did make a little applet to test the memory and the problem stayed.
    The example is in this URL :
    http://148.245.60.225/matematicas/bugs/JRE_memory_leak.html
    I don't know what i did do wrong. Can help me somebody?

    Yes - there is at least one serious memory leak in 08:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6462383
    Update 08 has been pulled and is not available on the Java pages anymore except for developers. I assume this was a real lemon.
    I had an issue with it because it changed the meaning of the EST time zone...

  • Applet calling javascript function causing memory leak

    Hi,
    I'm troubleshooting one memory leak issue in my application and to do that I created one simple Java applet and HTML + javascript function to locate the problem.
    Basically it's an applet calling a javascript function using a timer. The javascript function simply does nothing.
    I tested in IE 8.0 and JRE 1.6.0_23-b05 and memory of IE keeps increasing.
    I saw this bug http://bugs.sun.com/view_bug.do?bug_id=6857340 which seems related with my issue, but if I understand correctly from the page, the issue should have been fixed.
    I posted this message to find out if others also find same issue and if there's a solution for this. If I comment out window.call("dummy", null); , memory will not climb up.
    Java code
    +public class Main extends Applet implements Runnable  {+
    public Applet currentApplet= this ;
    +     public JSObject window = null;+
    +public void run(){+
    +          System.out.println("run..");+
    +     }+
    +public void start(){+
    window = JSObject.getWindow(this);
    int delay = 300; //milliseconds
    +ActionListener taskPerformer = new ActionListener() {+
    +public void actionPerformed(ActionEvent evt) {+
    window.call("dummy", null);
    +}+
    +};+
    new Timer(delay, taskPerformer).start();
    +     }+
    +public static void main(String[] args) {+
    +          System.out.println("start...");+
    +          Main main = new Main();+
    +     main.start();+
    +     }+
    +}+
    Javascript source code
    +<html>+
    +<head>+
    +<script>+
    +function dummy() {+
    +     +
    +}+
    +</script>+
    +</head>+
    +<body>+
    +<applet .... >+
    +...+
    +</html>+

    Try this url:
    http://www.inquiry.com/techtips/java_pro/10MinuteSolutions/callingJavaScript.asp
    It also provides some examples.

  • Applet load and memory leak

    what are some methods to load an applet faster that is on the local machine? also, are there any applications to test for memory leaks? and are there ways to invoke garbage collection with code? thanx in advance.

    Applet on the local machine will load faster because file is already there
    use System.gc() to do a garbage collection

  • Memory Leak on Applet Refresh in IE

    Hi All,
    This is really strange, if you have launched an java applet in IE and hit refresh, the the memory consumed by IE increses.Ideally speaking the consumed memory in task manager by IE with applet should show same if you hit refresh.But it grows.There is a memory leak.
    There was a bug [http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4894522] filed and claims to be fixed in 1.4..well i dont see it fixed in 1.6 either.
    Any thoughts..??
    Ex: First launch 45MB is being by applet ..hit refresh it goes to 80MB...and this goes untill a point and the incrementation of memory consumed becomes smaller and control becomes very slow.
    Thanks,
    Ranjitha

    More likely a bug in your applet. Not that there's not bugs, but more often than not, the fault is yours, not Java's.
    That's a whole lot of memory usage. That suggests that you are loading up a bunch of stuff, then holding onto it in the applet reference, maybe some static fields, then creating a whole new set of objects the second time.
    Static fields are not discarded, nor are classes unloaded (or technically because classes are not unloaded), when the browser is refreshed. So if you don't dispose of things, they may linger.
    Of course, resetting a static field should make the old objects go out of scope and eligible for GC.
    So maybe some explanation of what you're doing in your applet would go a long way towards figuring it out.

Maybe you are looking for