Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Detecting memory leak with Junit

 
Ali Ekber
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to JUnit and was wondering if JUnit can detect possible memory leaks in a large application. Thx.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it can't.

That is, by itself it can't. Of course you might be able to write a JUnit test that can figure out whether there was a memory leak but then it's not really JUnit doing it... (you could try a very primitive--and somewhat unreliable--analysis with totalMemory() and freeMemory() from the java.lang.Runtime class)

Or you could just use a profiling tool that can detect memory leaks. I haven't used one for finding memory leak in a while but at least OptimizeIT and JProbe advertize memory leak detection in their feature lists. JProfiler might also help in locating the leaks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic