2

我的 viewDidLoad 中的这个 @try-@catch 块在返回时与 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 中运行,以检索在应用程序的先前运行期间已存档的数据。我在这段代码中遇到了一个异常,指出存档无法理解。但是随着它崩溃,根本无法让应用程序运行,因为它在启动时和捕获时都会崩溃。有任何想法吗?

4

1 回答 1

2

您的assetsGroupURLorthumbnails_array属性(或两者)被声明为retain. 这很好,但这意味着当您同时调用[self.theProperty release]and时self.theProperty = nil,您将释放theProperty两次:第二次调用使用retain-generated 设置器并隐式调用release其当前值。删除release调用,您应该不再看到 EXC_BAD_ACCESS。

于 2012-02-10T17:31:23.420 回答