From 9d406a790123c0895900937c8ca5daeb8f6fb8b9 Mon Sep 17 00:00:00 2001 From: Huang-Libo Date: Mon, 15 Nov 2021 03:00:05 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E8=87=AA=E5=8A=A8=E9=87=8A=E6=94=BE?= =?UTF-8?q?=E6=B1=A0=E7=9A=84=E5=89=8D=E4=B8=96=E4=BB=8A=E7=94=9F.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加「关于 `kill()` 方法调用的解读」 --- ...15\344\270\226\344\273\212\347\224\237.md" | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git "a/contents/objc/\350\207\252\345\212\250\351\207\212\346\224\276\346\261\240\347\232\204\345\211\215\344\270\226\344\273\212\347\224\237.md" "b/contents/objc/\350\207\252\345\212\250\351\207\212\346\224\276\346\261\240\347\232\204\345\211\215\344\270\226\344\273\212\347\224\237.md" index 9f222be..bc943ac 100644 --- "a/contents/objc/\350\207\252\345\212\250\351\207\212\346\224\276\346\261\240\347\232\204\345\211\215\344\270\226\344\273\212\347\224\237.md" +++ "b/contents/objc/\350\207\252\345\212\250\351\207\212\346\224\276\346\261\240\347\232\204\345\211\215\344\270\226\344\273\212\347\224\237.md" @@ -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(); + } } ```