Application.addResource & removeResource

When does a Resource (such as FileResource) get removed from the Application?
Do we have to remove it via code (by calling Application.removeResource())? If that is the case, where exactly it has to happen?
If we don’t remove it, a long running application may accumulate a lot of ‘resources’ and the garbage collector doesn’t catch it because of the reference from the Application.

Hi, am worried about the same mater too.

I’d expect at least that extra resources would become reclaimed by garbage collector after Vaadin application closes (server session expires). In situations with a long session life times it may not be sufficient to rely on implicit behavior and would be better to put a custom resource management into the process. How to do it exactly I am not sure though. Often it’s even not exactly clear how to recognize specific resource is no longer needed to be kept registered (like when client finished downloading served file or image).

My application does generate a lot of downloads and I had used an InputStream with the method close() overridden so that I could intercept the corresponding Resource to remove it from the Application. This is not working in cases where Resource is used more than once to download.

I find it quite interesting that this single post about memory issue doesn’t get much attention, especially from Vaadin team. Our product platform UI is totally Vaadin based and is the foundation of many high throughput/concurrency applications. Hence, good memory utilisation is always the top factor. Having to always use a workaround for this is a big trade-off for convenience. I happened to revisit this old matter but still no decent solution yet.

Tien