You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by robert burrell donkin <ro...@blueyonder.co.uk> on 2003/04/14 23:41:39 UTC

[beanutils] any ideas about how to create a unit test for memory leaks?

i've been playing with the beanutils instance per classloader code using a 
weak hash map (as well as a release method) for a while now. i was 
wondering if anyone knows how to create a good, reliable test that this 
code works as advertised (it should recycle the classloader and the utils 
instance when the classloader is eligable for for garbage collection).

- robert


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


Re: [beanutils] any ideas about how to create a unit test for memory leaks?

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
thanks Juozas - this seems to work pretty well :)

- robert

On Tuesday, April 15, 2003, at 05:25 PM, Juozas Baliuka wrote:

> I am not sure it will work, but we can try it:
>
> Hold weak refernce on classloader:
>
> void testMemoryLeak(){
>  ClassLoader loader = new MyClassLoader();
>  WeakRefernce reference = new  WeakRefernce(loader);
>  Class myClass = loader.load(SOME_CLASS);
>   myClass.getMethod( ...).invoke(...) //invoke static methods.
> // derefernce class loader and class:
> long freeMemory = Runtime.freeMemory();
>
>  loader = null;
>  myClass = null;
>  int iterations = 0;
>   while(true){
>    System.gc();
>    if( iterations++ > SOME_CONSTANT ){
>       fail("gc is dissbled or memory leak");
>    }
>      if( reference.get() == null ) {
>          break;
>       }else{
>        //create garbage:
>       byte[] b =  new byte[SOME_CONST2];
>      }
>    }
>  }
>
> }
>
> Not a very good way, but can work.
>
>
> ----- Original Message -----
> From: "robert burrell donkin" <ro...@blueyonder.co.uk>
> To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
> Sent: Monday, April 14, 2003 11:41 PM
> Subject: [beanutils] any ideas about how to create a unit test for memory
> leaks?
>
>
>> i've been playing with the beanutils instance per classloader code using 
>> a
>> weak hash map (as well as a release method) for a while now. i was
>> wondering if anyone knows how to create a good, reliable test that this
>> code works as advertised (it should recycle the classloader and the utils
>> instance when the classloader is eligable for for garbage collection).
>>
>> - robert
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


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


Re: [beanutils] any ideas about how to create a unit test for memory leaks?

Posted by Juozas Baliuka <ba...@centras.lt>.
I am not sure it will work, but we can try it:

Hold weak refernce on classloader:

void testMemoryLeak(){
 ClassLoader loader = new MyClassLoader();
 WeakRefernce reference = new  WeakRefernce(loader);
 Class myClass = loader.load(SOME_CLASS);
  myClass.getMethod( ...).invoke(...) //invoke static methods.
// derefernce class loader and class:
long freeMemory = Runtime.freeMemory();

 loader = null;
 myClass = null;
 int iterations = 0;
  while(true){
   System.gc();
   if( iterations++ > SOME_CONSTANT ){
      fail("gc is dissbled or memory leak");
   }
     if( reference.get() == null ) {
         break;
      }else{
       //create garbage:
      byte[] b =  new byte[SOME_CONST2];
     }
   }
 }

}

Not a very good way, but can work.


----- Original Message -----
From: "robert burrell donkin" <ro...@blueyonder.co.uk>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Monday, April 14, 2003 11:41 PM
Subject: [beanutils] any ideas about how to create a unit test for memory
leaks?


> i've been playing with the beanutils instance per classloader code using a
> weak hash map (as well as a release method) for a while now. i was
> wondering if anyone knows how to create a good, reliable test that this
> code works as advertised (it should recycle the classloader and the utils
> instance when the classloader is eligable for for garbage collection).
>
> - robert
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


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