Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 自动释放池的前世今生.md #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions contents/objc/自动释放池的前世今生.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,23 @@ static inline void pop(void *token) {
2. 调用 `releaseUntil` 方法释放**栈中的**对象,直到 `stop`
3. 调用 `child` 的 `kill` 方法

> 我到现在也不是很清楚为什么要根据当前页的不同状态 `kill` 掉不同 `child` 的页面。
> ~~我到现在也不是很清楚为什么要根据当前页的不同状态 `kill` 掉不同 `child` 的页面。~~

关于 `kill()` 方法调用的解读:

- 如果 `page->child` 存在,则调用 `page->lessThanHalfFull()` 方法检测“当前 `page` 存储的内容是否超过一半”:
- 不超过一半,则删除 `page->child` 及之后的节点;
- 超过一半,则保留 `page->child` ,删除 `page->child->child` 及之后的节点。

```objectivec
if (page->lessThanHalfFull()) {
page->child->kill();
} else if (page->child->child) {
page->child->child->kill();
if (page->child) {
// hysteresis: keep one empty child if page is more than half full
if (page->lessThanHalfFull()) {
page->child->kill();
}
else if (page->child->child) {
page->child->child->kill();
}
}
```

Expand Down