You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2007/08/23 12:51:17 UTC

svn commit: r568928 - /cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/event/DispatchQueue.java

Author: aadamchik
Date: Thu Aug 23 03:51:17 2007
New Revision: 568928

URL: http://svn.apache.org/viewvc?rev=568928&view=rev
Log:
CAY-770 bug / memory leak in DispatchQueue and EventManager

Modified:
    cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/event/DispatchQueue.java

Modified: cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/event/DispatchQueue.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/event/DispatchQueue.java?rev=568928&r1=568927&r2=568928&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/event/DispatchQueue.java (original)
+++ cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/event/DispatchQueue.java Thu Aug 23 03:51:17 2007
@@ -59,12 +59,28 @@
     }
 
     synchronized void addInvocation(Invocation invocation, Object sender) {
+        Collection invocations;
+
         if (sender == null) {
-            subjectInvocations.add(invocation);
+            invocations = subjectInvocations;
         }
         else {
-            invocationsForSender(sender, true).add(invocation);
+            invocations = invocationsForSender(sender, true);
         }
+
+        // perform maintenance of the given invocations set, as failure to do taht can
+        // result in a memory leak per CAY-770. This seemed to happen when lots of
+        // invocations got registered, but no events where dispatched (hence the stale
+        // inocation removal during dispatch did not happen)
+        Iterator it = invocations.iterator();
+        while (it.hasNext()) {
+            Invocation i = (Invocation) it.next();
+            if (i.getTarget() == null) {
+                it.remove();
+            }
+        }
+
+        invocations.add(invocation);
     }
 
     synchronized boolean removeInvocations(Object listener, Object sender) {