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 useThreadLocal
storage [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
native
true 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 JDKnoclassgc
option, 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
ContextClassLoader
orccessControlContext
,
and useThreadGroup
orInheritedThreadLocal
.
They affectjava.util.concurrent.Executor
Not use
ThreadLocal
as cache unless truly necessary.
If thread not in it’s life cycle, loadContextClassLoader
, gc can’t reach it.When
ThreadGroup
have no subThread
but havesub ThreadGroup
callThreadGroup.destroy()
.
It lead to thissub ThreadGroup
can’t remove from it’sparent ThreadGroup
.use WeakHashMap, value hold key reference..