gpt4 book ai didi

ios - 什么是自动释放范围?

转载 作者:行者123 更新时间:2023-11-28 23:07:55 24 4
gpt4 key购买 nike

是否有可能在 [self saveContext] 之前释放测试对象?

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Test" inManagedObjectContext:[self managedObjectContext]];
for (int i = 0; i < 10; i++)
{
Test *test = [[[Test alloc] initWithEntity:entity insertIntoManagedObjectContext:[self managedObjectContext]] autorelease];
test.text = @"Text";
test.index = [NSNumber numberWithInt:i];
}
[self saveContext];

最佳答案

是的。但我认为这需要一个线程。

任何时候一个对象被发送-autorelease,它被添加到最高级别的自动释放池。只要您不在方法 B 中或在调用堆栈的下方创建任何新的自动释放池,方法 A 的池就应该是最高级别的池。

在这里形成 What is the scope of (nested) autorelease pools?

关于ios - 什么是自动释放范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8961976/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com