Creating memory leaks - Java
Static field holding object reference [esp final field]
class MemorableClass {
static final ArrayList list = new ArrayList(100);
}
Calling
String.intern()
on lengthy StringString str=readString(); // read lengthy string any source db,textbox/jsp etc..
// This will place the string in memory pool from which you cant remove
str.intern();
(Unclosed) open streams ( file , network etc... )
try {
BufferedReader br = new BufferedReader(new FileReader(inputFile));
...
...
} catch (Exception e) {
e.printStacktrace();
}
Unclosed connections
try {
Connection conn = ConnectionFactory.getConnection();
...
...
} catch (Exception e) {
e.printStacktrace();
}
Areas that are unreachable from JVM's garbage collector, such as memory allocated through native methods
In web applications, some objects are stored in application scope until the application is explicitly stopped or removed.
getServletContext().setAttribute("SOME_MAP", map);
Incorrect or inappropriate JVM options, such as the
noclassgc
option on IBM JDK that prevents unused class garbage collection
Ref: Stackoverflow
Comments
Post a Comment