hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-hivemind/framework/src/java/org/apache/hivemind/util EventListenerList.java
Date Wed, 07 Apr 2004 15:17:27 GMT
hlship      2004/04/07 08:17:27

  Modified:    framework/src/test/hivemind/test/util
                        TestEventListenerList.java
               framework/src/java/org/apache/hivemind/util
                        EventListenerList.java
  Log:
  [HIVEMIND-2] EventListenerList leaks memory
  
  Revision  Changes    Path
  1.4       +32 -1     jakarta-hivemind/framework/src/test/hivemind/test/util/TestEventListenerList.java
  
  Index: TestEventListenerList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/util/TestEventListenerList.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestEventListenerList.java	26 Feb 2004 23:08:04 -0000	1.3
  +++ TestEventListenerList.java	7 Apr 2004 15:17:27 -0000	1.4
  @@ -16,7 +16,9 @@
   
   import hivemind.test.FrameworkTestCase;
   
  +import java.util.ArrayList;
   import java.util.Iterator;
  +import java.util.List;
   
   import org.apache.hivemind.util.EventListenerList;
   
  @@ -192,6 +194,35 @@
           }
           catch (UnsupportedOperationException ex)
           {
  +        }
  +    }
  +
  +    public void testOutOfMemoryError()
  +    {
  +        Trigger ta = buildTriggers(1)[0];
  +        EventListenerList l = new EventListenerList();
  +        List iterators = new ArrayList();
  +
  +        try
  +        {
  +            for (int i = 0; i < 100; i++)
  +            {
  +                l.addListener(ta);
  +
  +                iterators.add(l.getListeners());
  +
  +                l.removeListener(ta);
  +
  +            }
  +
  +        }
  +        catch (OutOfMemoryError e)
  +        {
  +            fail("Ran out of memory!");
  +        }
  +        catch (Throwable e)
  +        {
  +            fail(e.getMessage());
           }
       }
   }
  
  
  
  1.2       +7 -1      jakarta-hivemind/framework/src/java/org/apache/hivemind/util/EventListenerList.java
  
  Index: EventListenerList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/util/EventListenerList.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EventListenerList.java	26 Feb 2004 23:07:54 -0000	1.1
  +++ EventListenerList.java	7 Apr 2004 15:17:27 -0000	1.2
  @@ -158,6 +158,12 @@
           {
               int nominalSize = (size == 0) ? START_SIZE : 2 * size;
   
  +            // Don't grow the array if we don't need to...
  +            if (size >= requiredSize)
  +            {
  +                nominalSize = size;
  +            }
  +
               int newSize = Math.max(requiredSize, nominalSize);
   
               Object[] newListeners = new Object[newSize];
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message