gpt4 book ai didi

iphone - ios @try @catch 在从@catch 返回时阻止 EXC_BAD_ACCESS

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:23:29 25 4
gpt4 key购买 nike

我的 viewDidLoad 中的这个 @try-@catch block 在返回时因 EXC_BAD_ACCESS 而崩溃;在 catch 中执行并且警报不显示:

    @try
{
errorText = @"thumbnails_array";

unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
// Customize unarchiver here
self.thumbnails_array = [unarchiver decodeObjectForKey:@"thumbnails_array"];
[unarchiver finishDecoding];
[unarchiver release];


errorText = @"ThumbNailViewController";

archivePath = [app.phojoArchiveDir stringByAppendingPathComponent:@"ThumbNailViewController.archive"];
data = [NSData dataWithContentsOfFile:archivePath];
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
// Customize unarchiver here
[unarchiver decodeObjectForKey:@"self"];
[unarchiver finishDecoding];
[unarchiver release];

errorText = @"assetsGroupURL";

archivePath = [app.phojoArchiveDir stringByAppendingPathComponent:@"assetsGroupURL.archive"];
data = [NSData dataWithContentsOfFile:archivePath];
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
// Customize unarchiver here
app.assetsGroupURL = [unarchiver decodeObjectForKey:@"assetsGroupURL"];
[unarchiver finishDecoding];
[unarchiver release];


}
@catch (NSException *exception)
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Phojo is unable to restore the previous editing session." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];

NSLog(@"Exception %@ thrown while unarchving %@: Reason: %@ Items in userInfo = %d Stack Trace: %@", [exception name], errorText, [exception reason], [[exception userInfo] count], [NSThread callStackSymbols]);
[self.thumbnails_array release];
self.thumbnails_array = nil;
[app.assetsGroupURL release];
app.assetsGroupURL = nil;

return;


}

此代码在 viewDidLoad 中运行,以检索在上一次应用程序运行期间存档的数据。我在这段代码中遇到了一个异常,指出存档是不可理解的。但是随着它崩溃,根本没有办法让应用程序运行,因为它在启动时和捕获时都崩溃了。有什么想法吗?

最佳答案

您的 assetsGroupURLthumbnails_array 属性(或两者)被声明为 retain。这很好,但这意味着当您同时调用 [self.theProperty release]self.theProperty = nil 时,您正在释放 theProperty两次:第二次调用是使用 retain 生成的 setter 并在其当前值上隐式调用 release。删除 release 调用,您应该不会再看到 EXC_BAD_ACCESS。

关于iphone - ios @try @catch 在从@catch 返回时阻止 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9231962/

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