leif 02/02/20 22:45:14
Modified: src/test/org/apache/avalon/excalibur/component/test
ExcaliburComponentManagerTestCase.java
Log:
Add some code to track down a memory leak.
Revision Changes Path
1.5 +35 -1
jakarta-avalon-excalibur/src/test/org/apache/avalon/excalibur/component/test/ExcaliburComponentManagerTestCase.java
Index: ExcaliburComponentManagerTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/src/test/org/apache/avalon/excalibur/component/test/ExcaliburComponentManagerTestCase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ExcaliburComponentManagerTestCase.java 21 Feb 2002 06:18:11 -0000
1.4
+++ ExcaliburComponentManagerTestCase.java 21 Feb 2002 06:45:14 -0000
1.5
@@ -12,8 +12,9 @@
import org.apache.avalon.excalibur.component.ExcaliburComponentManager;
import org.apache.avalon.excalibur.util.ComponentStateValidator;
-import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.logger.LogKitLogger;
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.Configuration;
@@ -39,7 +40,7 @@
* it is correctly handling component lifestyle management.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ryan Shaw</a>
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class ExcaliburComponentManagerTestCase extends TestCase
{
@@ -115,9 +116,28 @@
return suite;
}
+ protected long resetMemory()
+ {
+ System.gc();
+ System.gc();
+
+ // Let the system settle down.
+ try
+ {
+ Thread.sleep( 50 );
+ }
+ catch (InterruptedException e ) {}
+ Runtime runtime = Runtime.getRuntime();
+ long memory = runtime.totalMemory() - runtime.freeMemory();
+ //m_logger.debug( "Memory: " + memory );
+ return memory;
+ }
+
protected void managerLifecycle(Class momClass, Class dadClass, Class
kidClass)
throws Exception
{
+ long startMemory = resetMemory();
+
Configuration emptyConfig = new DefaultConfiguration( "", "" );
m_manager.addComponent( Mom.ROLE, momClass, emptyConfig );
@@ -130,11 +150,21 @@
Component dad = m_manager.lookup( Dad.ROLE );
m_manager.release( mom );
+ mom = null;
m_manager.release( dad );
+ dad = null;
m_manager.dispose();
+ m_manager = null;
+ emptyConfig = null;
checkNumberOfDisposals( momClass, dadClass, kidClass );
+
+ long endMemory = resetMemory();
+
+ m_logger.info("Test start memory=" + startMemory +
+ " end memory=" + endMemory +
+ " diff=" + (endMemory - startMemory));
}
private void checkNumberOfDisposals( Class momClass, Class dadClass,
Class kidClass )
@@ -392,6 +422,8 @@
private ExcaliburComponentManager m_manager;
+ private Logger m_logger;
+
public ExcaliburComponentManagerTestCase( String name )
{
super( name );
@@ -415,6 +447,8 @@
m_manager.setLogger( logger );
m_manager.contextualize( new DefaultContext() );
m_manager.configure( new DefaultConfiguration( "", "" ) );
+
+ m_logger = new LogKitLogger( logger );
}
public void tearDown()
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>