5 Replies Latest reply: Mar 8, 2012 1:59 PM by Rich DiCroce RSS

Arquillian not cleaning up after itself?

Rich DiCroce Novice

I have a project with (so far) 17 test classes containing over 100 test methods. When I try to run all my tests in one go, I end up getting a PermGen OutOfMemoryError. This happens because the test EAR has to be redeployed for each class, and AS7's classloading system recreates all my classes over and over. My understanding is that classes should get garbage collected when they're no longer needed, so I analyzed some heap dumps to find out why that wasn't happening.

 

Turns out that something is putting a TestNG result in a ThreadLocal on a thread in the container and never clearing it. This is a problem because the test result class is part of the deployment, and it holds a reference to the classloader that loaded the deployment, which holds references to all the other classes in the deployment. Since Arquillian doesn't restart JBoss between test classes (and, by extension, deployments), all the classes from all the deployments accumulate until the PermGen space is exhausted. I can try upping the PermGen space as a workaround, but every test class I add will make the problem progressively worse, so it would be much better to fix the leak.

 

So, is this ThreadLocal usage something Arquillian is doing? Or is it something TestNG is doing?