lundi 29 décembre 2014

What happens with references to window when we close it and how to prevent this memory leakage?

I'm interested in the issue of preventing memory leakages in long life java applications. So let's say we create a window for each user in some server side application. We have someone who is specifically develops this window. The developer of this window does something at onClose(), but the references to this window are still there. Which means that if the end user of that window has put some 1MB image into this window via some reference, then for 1000 users we'll have 1GB un-freed memory.


What is the common way (maybe some design pattern) to prevent such memory leakage in long life applications?


I'm reading this article in JavaWorld and I see that in the end it solves something that is related to references inside listeners. I don't understand the connection of it to this problem.


I do understand that we can simply create an external listeners which'll put null into all of the references to that window once it is closed, however I don't think it's the best solution (e.g. think of what happens when someone create a reference and forgets to add such a listener!).


Aucun commentaire:

Enregistrer un commentaire