xpoft / spring-vaadin

Spring and Vaadin integration
Other
55 stars 44 forks source link

Memory leak in DiscoveryNavigator #41

Open tohyuon opened 9 years ago

tohyuon commented 9 years ago

I noticed a memory leak in the DiscoveryNavigator class.

The DiscoveryNavigator class contains the static field "views" with a list of ViewCache objects. This list gets initialized in the initViews method that is invoked by the constructor.

The ViewCache class is a non-static embedded class of the DiscoveryNavigator, which means that it keeps an implicit reference to the containing (DiscoveryNavigator) instance.

Due to the static field and the implicit reference, the very first DiscoveryNavigator instance will never become garbage collected. Since the Navigator also keeps a reference to the UI instance, this means that the UI instance and all its referenced objects cannot be garbage collected either.

(static field DiscoveryNavigator.views -> List of DiscoveryNavigator.ViewCache instances -> DiscoveryNavigator instance -> UI instance)

The solution to this issue is to declare the embedded ViewCache class static.