You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by dv...@apache.org on 2012/10/01 21:17:29 UTC

svn commit: r1392528 - in /pig/trunk: CHANGES.txt src/org/apache/pig/impl/util/SpillableMemoryManager.java

Author: dvryaboy
Date: Mon Oct  1 19:17:29 2012
New Revision: 1392528

URL: http://svn.apache.org/viewvc?rev=1392528&view=rev
Log:
PIG-2917: SpillableMemoryManager memory leak for WeakReference

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/impl/util/SpillableMemoryManager.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1392528&r1=1392527&r2=1392528&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Mon Oct  1 19:17:29 2012
@@ -285,6 +285,8 @@ OPTIMIZATIONS
 
 BUG FIXES
 
+PIG-2917: SpillableMemoryManager memory leak for WeakReference (haitao.yao via dvryaboy)
+
 PIG-2938: All unit tests that use MR2 MiniCluster are broken in trunk (cheolsoo via dvryaboy)
 
 PIG-2936: Tuple serialization bug (jcoveney)

Modified: pig/trunk/src/org/apache/pig/impl/util/SpillableMemoryManager.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/impl/util/SpillableMemoryManager.java?rev=1392528&r1=1392527&r2=1392528&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/impl/util/SpillableMemoryManager.java (original)
+++ pig/trunk/src/org/apache/pig/impl/util/SpillableMemoryManager.java Mon Oct  1 19:17:29 2012
@@ -181,22 +181,13 @@ public class SpillableMemoryManager impl
             }
 
         }
-         
+        clearSpillables();
         if (toFree < 0) {
             log.debug("low memory handler returning " + 
                 "because there is nothing to free");
             return;
         }
         synchronized(spillables) {
-            // Walk the list first and remove nulls, otherwise the sort
-            // takes way too long.
-            Iterator<WeakReference<Spillable>> i;
-            for (i = spillables.iterator(); i.hasNext();) {
-                Spillable s = i.next().get();
-                if (s == null) {
-                    i.remove();
-                }
-            }
             Collections.sort(spillables, new Comparator<WeakReference<Spillable>>() {
 
                 /**
@@ -233,7 +224,7 @@ public class SpillableMemoryManager impl
             long estimatedFreed = 0;
             int numObjSpilled = 0;
             boolean invokeGC = false;
-            for (i = spillables.iterator(); i.hasNext();) {
+            for (Iterator<WeakReference<Spillable>> i = spillables.iterator(); i.hasNext();) {
                 Spillable s = i.next().get();
                 // Still need to check for null here, even after we removed
                 // above, because the reference may have gone bad on us
@@ -280,6 +271,19 @@ public class SpillableMemoryManager impl
         }
     }
     
+    public void clearSpillables() {
+        synchronized (spillables) {
+            // Walk the list first and remove nulls, otherwise the sort
+            // takes way too long.
+            for (Iterator<WeakReference<Spillable>> i = spillables.iterator(); i
+                    .hasNext();) {
+                Spillable s = i.next().get();
+                if (s == null) {
+                    i.remove();
+                }
+            }
+        }
+    }
     /**
      * Register a spillable to be tracked. No need to unregister, the tracking will stop
      * when the spillable is GCed.