Project

General

Profile

Revision bba20239

IDbba202394eb654dfbdba5a8e7feeda461635157e
Parent 23cee55f
Child 67bf2db8

Added by Andreas Kohlbecker almost 2 years ago

fix #7824 cleaning up maps in PopupViewRegistration when views are detached - closes memory leak

View differences:

src/main/java/eu/etaxonomy/vaadin/ui/navigation/NavigationManagerBean.java
133 133
		} else {
134 134
			super.navigateTo(navigationState);
135 135
		}
136
		popupViewRegistration.removeOrphan();
137 136
	}
138 137

  
139 138
	@Override
......
143 142
	    }
144 143
		super.navigateTo(navigationState);
145 144
		//eventBus.publishEvent(new NavigationEvent(navigationState));
146
		popupViewRegistration.removeOrphan();
147 145
	}
148 146

  
149 147
	@EventBusListenerMethod
src/main/java/eu/etaxonomy/vaadin/ui/navigation/PopupViewRegistration.java
11 11
import java.util.HashMap;
12 12
import java.util.Map;
13 13

  
14
import org.apache.log4j.Logger;
15

  
16
import com.vaadin.server.ClientConnector;
17
import com.vaadin.server.ClientConnector.DetachEvent;
18
import com.vaadin.server.ClientConnector.DetachListener;
14 19
import com.vaadin.ui.Field;
15 20
import com.vaadin.ui.Window;
16 21

  
......
22 27
 * @since May 16, 2018
23 28
 *
24 29
 */
25
public class PopupViewRegistration {
30
public class PopupViewRegistration implements DetachListener {
31

  
32
    private static final long serialVersionUID = -5946913287379095637L;
33

  
34
    private static final Logger logger = Logger.getLogger(PopupViewRegistration.class);
26 35

  
27 36
    private Map<PopupView, Window> popupWindowMap = new HashMap<>();
28 37

  
......
36 45
     */
37 46
    public Field<?> put(Window window, ApplicationView parentView, PopupView popup, Field<?> field){
38 47

  
48
        ((ClientConnector)parentView).addDetachListener(this);
39 49
        popupWindowMap.put(popup, window);
40 50

  
41 51
        if(!popupViewFieldMap.containsKey(parentView)){
......
71 81
        for(Map<PopupView, Field<?>> popupFieldMap : popupViewFieldMap.values()){
72 82
            if(popupFieldMap.containsKey(popup)){
73 83
                popupFieldMap.remove(popup);
84
                if(logger.isDebugEnabled()){
85
                    logger.debug(popup +  " removed from popupViewFieldMap");
86
                }
74 87
            }
75 88
        }
76 89
    }
......
84 97
    }
85 98

  
86 99
    /**
87
     *
100
     * {@inheritDoc}
88 101
     */
89
    public void removeOrphan() {
90
        // unimplemented, only needed in case of memory leaks due to lost popups
102
    @Override
103
    public void detach(DetachEvent event) {
104
        ClientConnector connector = event.getConnector();
105
        if(ApplicationView.class.isAssignableFrom(connector.getClass())){
106
            Map<PopupView, Field<?>> removal = popupViewFieldMap.remove(connector);
107
            if(logger.isDebugEnabled() && removal != null){
108
                logger.debug( connector +  " removed from popupViewFieldMap");
109
            }
110
        } else if(PopupView.class.isAssignableFrom(connector.getClass())){
111
            remove((PopupView)connector);
112
        }
113

  
91 114
    }
92 115

  
93 116
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)