]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed #723 (Critical memory leak)
authorJani Laakso <jani.laakso@itmill.com>
Tue, 15 May 2007 20:14:06 +0000 (20:14 +0000)
committerJani Laakso <jani.laakso@itmill.com>
Tue, 15 May 2007 20:14:06 +0000 (20:14 +0000)
svn changeset:1440/svn branch:trunk

src/com/itmill/toolkit/terminal/web/ApplicationServlet.java
src/com/itmill/toolkit/terminal/web/ThemeFunctionLibrary.java

index 3d93114c180d931c4a0a83f2be9a60b789664d89..99c315e5c935c5746ee64e90ae147d9a10053a55 100644 (file)
@@ -44,7 +44,6 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Enumeration;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -523,7 +522,7 @@ public class ApplicationServlet extends HttpServlet implements
                UIDLTransformer transformer = null;
                HttpVariableMap variableMap = null;
                OutputStream out = response.getOutputStream();
-               HashSet currentlyDirtyWindowsForThisApplication = new HashSet();
+               WeakHashMap currentlyDirtyWindowsForThisApplication = new WeakHashMap();
                Application application = null;
                try {
 
@@ -755,15 +754,16 @@ public class ApplicationServlet extends HttpServlet implements
                                        paintTarget.close();
 
                                        // For exception handling, memorize the current dirty status
-                                       Collection dirtyWindows = (Collection) applicationToDirtyWindowSetMap
+                                       WeakHashMap dirtyWindows = (WeakHashMap) applicationToDirtyWindowSetMap
                                                        .get(application);
+
                                        if (dirtyWindows == null) {
-                                               dirtyWindows = new HashSet();
+                                               dirtyWindows = new WeakHashMap();
                                                applicationToDirtyWindowSetMap.put(application,
                                                                dirtyWindows);
                                        }
                                        currentlyDirtyWindowsForThisApplication
-                                                       .addAll(dirtyWindows);
+                                                       .putAll((Map) dirtyWindows);
 
                                        // Window is now painted
                                        windowPainted(application, window);
@@ -823,7 +823,7 @@ public class ApplicationServlet extends HttpServlet implements
                        // to make sure that eventually they are repainted
                        Application currentApplication = getApplication(request);
                        for (Iterator iter = currentlyDirtyWindowsForThisApplication
-                                       .iterator(); iter.hasNext();) {
+                                       .keySet().iterator(); iter.hasNext();) {
                                Window dirtyWindow = (Window) iter.next();
                                addDirtyWindow(currentApplication, dirtyWindow);
                        }
@@ -1712,13 +1712,13 @@ public class ApplicationServlet extends HttpServlet implements
         */
        protected void addDirtyWindow(Application application, Window window) {
                synchronized (applicationToDirtyWindowSetMap) {
-                       HashSet dirtyWindows = (HashSet) applicationToDirtyWindowSetMap
+                       WeakHashMap dirtyWindows = (WeakHashMap) applicationToDirtyWindowSetMap
                                        .get(application);
                        if (dirtyWindows == null) {
-                               dirtyWindows = new HashSet();
+                               dirtyWindows = new WeakHashMap();
                                applicationToDirtyWindowSetMap.put(application, dirtyWindows);
                        }
-                       dirtyWindows.add(window);
+                       dirtyWindows.put(window, Boolean.TRUE);
                }
        }
 
@@ -1729,7 +1729,7 @@ public class ApplicationServlet extends HttpServlet implements
         */
        protected void removeDirtyWindow(Application application, Window window) {
                synchronized (applicationToDirtyWindowSetMap) {
-                       HashSet dirtyWindows = (HashSet) applicationToDirtyWindowSetMap
+                       WeakHashMap dirtyWindows = (WeakHashMap) applicationToDirtyWindowSetMap
                                        .get(application);
                        if (dirtyWindows != null)
                                dirtyWindows.remove(window);
@@ -1791,12 +1791,13 @@ public class ApplicationServlet extends HttpServlet implements
         * @param app
         * @return
         */
-       protected Set getDirtyWindows(Application app) {
-               HashSet dirtyWindows;
+       protected Map getDirtyWindows(Application app) {
+               WeakHashMap dirtyWindows;
                synchronized (applicationToDirtyWindowSetMap) {
-                       dirtyWindows = (HashSet) applicationToDirtyWindowSetMap.get(app);
+                       dirtyWindows = (WeakHashMap) applicationToDirtyWindowSetMap
+                                       .get(app);
                }
-               return dirtyWindows;
+               return (Map) dirtyWindows;
        }
 
        /**
@@ -1875,13 +1876,14 @@ public class ApplicationServlet extends HttpServlet implements
                                        } else {
 
                                                // Application still alive - keep updating windows
-                                               Set dws = getDirtyWindows(application);
+                                               Map dws = getDirtyWindows(application);
                                                if (dws != null && !dws.isEmpty()) {
 
                                                        // For one of the dirty windows (in each
                                                        // application)
                                                        // request redraw
-                                                       Window win = (Window) dws.iterator().next();
+                                                       Window win = (Window) dws.keySet().iterator()
+                                                                       .next();
                                                        w
                                                                        .println("<script>\n"
                                                                                        + ThemeFunctionLibrary
@@ -1906,6 +1908,7 @@ public class ApplicationServlet extends HttpServlet implements
 
                                // Sends the generated commands and newline immediately to
                                // browser
+                               // TODO why space in here? why not plain ln?
                                w.println(" ");
                                w.flush();
                                response.flushBuffer();
index a7b62af8d74da66dd5f7e69d042427468199da6a..e03f6b3d91be022ad7308232778a7f28c0002875 100644 (file)
@@ -39,7 +39,7 @@ import java.util.Collection;
 import java.util.GregorianCalendar;
 import java.util.Iterator;
 import java.util.LinkedList;
-import java.util.Set;
+import java.util.Map;
 import java.util.Vector;
 
 import javax.servlet.http.HttpSession;
@@ -226,9 +226,9 @@ public class ThemeFunctionLibrary {
                LinkedList update = new LinkedList();
 
                // Adds all the windows needto update list
-               Set dirtyWindows = wa != null ? wa.getDirtyWindows(app) : null;
+               Map dirtyWindows = wa != null ? wa.getDirtyWindows(app) : null;
                if (dirtyWindows != null)
-                       for (Iterator i = dirtyWindows.iterator(); i.hasNext();) {
+                       for (Iterator i = dirtyWindows.keySet().iterator(); i.hasNext();) {
                                Window w = (Window) i.next();
                                if (w != window) {
                                        if (w instanceof FrameWindow)