autoreleaseNewPage(id obj)
static __attribute__((noinline)) id *autoreleaseNewPage(id obj)
{
AutoreleasePoolPage *page = hotPage();
if (page) return autoreleaseFullPage(obj, page);
else return autoreleaseNoPage(obj);
}
获取当前AutoreleasePoolPage,如果存在调用autoreleaseFullPage,否则调用autoreleaseNoPage
autoreleaseFullPage(id obj, AutoreleasePoolPage *page)
static __attribute__((noinline)) id *autoreleaseFullPage(id obj, AutoreleasePoolPage *page)
{
// The hot page is full.
// Step to the next non-full page, adding a new page if necessary.
// Then add the object to that page.
assert(page == hotPage());
assert(page->full() || DebugPoolAllocation);
do {
if (page->child) page = page->child;
else page = new AutoreleasePoolPage(page);
} while (page->full());
setHotPage(page);
return page->add(obj);
}
遍历子AutoreleasePoolPage,如果有未满的AutoreleasePoolPage设置为当前AutoreleasePoolPage并调用add函数将对象入栈。否则将新创建的子AutoreleasePoolPage设置为当前AutoreleasePoolPage并调用add函数将对象入栈
add(id obj)
id *add(id obj)
{
assert(!full());
unprotect();
id *ret = next; // faster than `return next-1` because of aliasing
*next++ = obj;
protect();
return ret;
}
|