### Eclipse Workspace Patch 1.0
#P jruby
Index: src/org/jruby/runtime/ObjectSpace.java
===================================================================
RCS file: /cvsroot/jruby/jruby/src/org/jruby/runtime/ObjectSpace.java,v
retrieving revision 1.7
diff -u -r1.7 ObjectSpace.java
--- src/org/jruby/runtime/ObjectSpace.java	16 Jun 2005 18:55:49 -0000	1.7
+++ src/org/jruby/runtime/ObjectSpace.java	6 Jun 2006 02:53:34 -0000
@@ -15,7 +15,7 @@
  * Copyright (C) 2002-2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
  * Copyright (C) 2004 Charles O Nutter <headius@headius.com>
  * Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
- * 
+ *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
@@ -49,24 +49,15 @@
  */
 public class ObjectSpace {
     private Set references = Collections.synchronizedSet(new HashSet());
-    private ReferenceQueue deadReferences = new ReferenceQueue();
 
     public void add(IRubyObject object) {
-        cleanup();
-        references.add(new WeakReference(object, deadReferences));
+        references.add(new WeakReference(object));
     }
 
     public Iterator iterator(RubyModule rubyClass) {
         return new ObjectSpaceIterator(rubyClass);
     }
 
-    private void cleanup() {
-        Reference reference;
-        while ((reference = deadReferences.poll()) != null) {
-            references.remove(reference);
-        }
-    }
-
     private class ObjectSpaceIterator implements Iterator {
         private final RubyModule rubyClass;
         private final Iterator iterator;
@@ -75,7 +66,7 @@
 
         public ObjectSpaceIterator(RubyModule rubyClass) {
             this.rubyClass = rubyClass;
-			
+
             synchronized(references) {
                 iterator = new ArrayList(references).iterator();
                 prefetch();
@@ -106,8 +97,12 @@
                     return;
                 }
                 WeakReference ref = (WeakReference) iterator.next();
+
                 next = (IRubyObject) ref.get();
-                if (next != null && next.isKindOf(rubyClass)) {
+
+                if (next == null) {
+                    iterator.remove();
+                } else if (next.isKindOf(rubyClass)) {
                     return;
                 }
             }
