commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <robertburrelldon...@blueyonder.co.uk>
Subject Re: [beanutils] any ideas about how to create a unit test for memory leaks?
Date Wed, 30 Apr 2003 09:37:39 GMT
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" <robertburrelldonkin@blueyonder.co.uk>
> To: "Jakarta Commons Developers List" <commons-dev@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


Mime
View raw message