<p>Let's suppose I have an applet running within a page in a browser.
What happens when the browser is closed by the user?</p>

<p>Is the applet notified so that it can perform some kind of close action on its side (closing connections opened to a server, cleaning static variables, ...)?</p>

<p>Also, I assume the same behavior would apply for a page refresh or page navigation (instead of browser close). The browser remains opened but the applet is gone. Although when you close the browser you also close the JVM so I'm unsure at this point.</p>

<p>Thanks,
JB</p>

Yes, the
destroy() method
should be called before the
browser unloads the object
.
destroy()
is the last of four "
life-cycle methods
" of the Java applet (the others are
init()
,
start()
, and
stop()
).  They're actually called at different times depending on your
browser
and
virtual machine
.  If you'd like to know exactly when each is called, implement each method within your applet, and System.out some feedback.
Ideally, destroy() should be
called by the environment
, and should only be called once.  If it seems like destroy() is not being called, you might declare a public finalize() method, which calls destroy.  You could also try to call destroy() from javascript as the window object unloads, but again, be sure that you're not calling destroy() unnecessarily.
```
```
public void finalize () {
    destroy();
}
```
```