返回时,我的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中运行,以检索在上一次运行该应用程序期间已存档的数据。我在此代码中出现了一个异常,指出存档令人难以理解。但是由于崩溃,它根本无法使应用程序运行,因为它在启动时以及崩溃时都会崩溃。有任何想法吗?

最佳答案

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

07-26 09:37