Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2741d4a

Browse filesBrowse files
committed
内容格式修改
在每一步后面添加了空白行,改进显示效果
1 parent 2dc09d9 commit 2741d4a
Copy full SHA for 2741d4a

File tree

Expand file treeCollapse file tree

1 file changed

+5
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-0
lines changed

‎contents/creating-a-memory-leak-with-java.md

Copy file name to clipboardExpand all lines: contents/creating-a-memory-leak-with-java.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55

66
## 解答
77
在Java下有一个很好的方法来创建内存泄漏程序--通过使得对象不可访问但任然存储在内存中。
8+
89
1. 应用程序创建一个长期运行的线程A 或者 使用一个线程池来加快泄漏的速度。
10+
911
2. 线程A使用ClassLoader(用户可以自定义)加载一个类 B
12+
1013
3. 在类B申请一块很大的连续内存(例如:new byte[1000000]),
1114
并使用一个静态成员变量中存储该空间的一个强引用,之后在一个ThreadLocal中存储类B对象的引用。
1215
虽然泄漏这个类的一个实例就足够了,但是也可以通过申请多个实例的方法来加快内存泄漏的速度。
16+
1317
4. 线程A清理所有指向自定义类或者通过ClassLoadeer加载的引用。
18+
1419
5. 重复上述步骤
1520

1621
上述方式可以达到内存泄漏的目的,因为 ThreadLocal 存储了一个指向类B对象的引用,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.