Living in a state of accord.

JUnit Memory Usage In Eclipse

If you happen to run a lot of JUnit tests in one go with Eclipse, you may find that towards the end they start to slow down or throw OutOfMemoryExceptions. They do that because the Eclipse JUnit plugin creates a new instance of the TestCase for each test method, calls setup, test method, tearDown and then for some reason keeps the object around. This means that if your tearDown doesn't null out all the fields in the test class you can wind up with a whole lot of wasted memory.

You'll have to have a whole heap of atomic tests before you notice this, but with about 1200 integration tests, today we started getting out of memory exceptions. Fortunately, there were only a few base classes that we needed to add clean up code to and everything's running smoothly again.

It's pretty annoying that Eclipse is wasting memory like that – why should we waste developer time just because the JUnit plugin is clingy?