EDIT: apparently this isn’t a threadlocal or Appfoundation issue, it was related to session management, which it would seem it’s pretty dangerous if left unchecked
I have a ThreadLocal variable set to the class extending Application (the entry point class), say MyApplication class.
It’s initialized and used like this:
@Override
public void transactionEnd(Application application, Object transactionData) {
...
if (application == ReallotoApplication.this) {
ReallotoApplication.currentApplication.set(null);
ReallotoApplication.currentApplication.remove();
}
}
@Override
public void transactionStart(Application application, Object transactionData) {
if (application == ReallotoApplication.this) {
ReallotoApplication.currentApplication.set(this);
}
}
The problem starts when I close the browser windows, which triggers this:
mainWindow.addListener(new Window.CloseListener() {
@Override
public void windowClose(CloseEvent e) {
if (ReallotoApplication.currentApplication.get() == ReallotoApplication.this) {
ReallotoApplication.currentApplication.set(null);
ReallotoApplication.currentApplication.remove();
}
close();
}
});
and this:
@Override
public void close() {
if (ReallotoApplication.currentApplication.get() == this) {
ReallotoApplication.currentApplication.set(null);
ReallotoApplication.currentApplication.remove();
}
super.close();
}
but watching in VisualVM, I see all the ReallotoApplication instances sticking after I closed the browser window (and close() triggered), and even if I call garbage collector from VisualVM a couple of times, they don’t go away, which means it’s a memory leak. I left for 30 mins, but they were still. I also tested if the session timeout was involved, it seemed not. Experimenting around it seems that only when I close the browser window on the application it remains stuck in memory, if I press exit which goes on to call close() it does not.
How to fix this please? I want the ReallotoApplication instances to go away after close() is triggered, or browser tab/window is closed
I’m using Tomcat 7.0.16.0 and Vaadin 6.7.3