Create some ghost memory
- Create a long exist thread or thread pool.
- Load a class through
ClassLoader. - Distribute a big block memory to a static strong reference.
Then useThreadLocalstorage [thread reference?] or [object reference?] - Thread clean selfdefine class or load this class’s loader.
- repeat these steps.
Some mistake
static reference hold container.
1
2
3class Holder {
static final List list = new ArrayList(100);
}call long String’s
intern()method1
2String src = "......";
str.intern();forgot release resource
1
2
3
4
5
6
7try {
BufferedReader br = new BufferedReader(new FileReader("..."));
...
...
} catch (Exception e) {
e.printStacktrace();
}forgot close door
1
2
3
4
5
6
7try {
Connection conn = ConnectionFactory.getConnection();
...
...
} catch (Exception e) {
e.printStacktrace();
}GC can’t reach like
nativetrue memoryWeb container in application context
getServletContext().setAttribute("rubbish", map);
no reboot and not remove rubbish.Web container in session context
session.setAttribute("rubbish", map);
no reboot / not invalid and not remove rubbish.Not right JVM option
IBM JDKnoclassgcoption, it stop no use class’s garbage collect.
Bean not define properly
If HashSet’s element object have no standard implement
or no implement of equals() and hashCode().
Collection can’t ignore repeated element.
Thread relevant
- Create but not start thread.
Thread inherited
ContextClassLoaderorccessControlContext,
and useThreadGrouporInheritedThreadLocal.
They affectjava.util.concurrent.ExecutorNot use
ThreadLocalas cache unless truly necessary.
If thread not in it’s life cycle, loadContextClassLoader, gc can’t reach it.When
ThreadGrouphave no subThread
but havesub ThreadGroupcallThreadGroup.destroy().
It lead to thissub ThreadGroupcan’t remove from it’sparent ThreadGroup.use WeakHashMap, value hold key reference..