1

我在 iPad 上有一个应用程序崩溃导致重新启动。此崩溃发生在方法 showMap:(Mappe *mappa) 之后的某处:

- (void)viewDidLoad {
    moc = [[MapFetcher sharedInstance] managedObjectContext];
    [NSThread detachNewThreadSelector:@selector(fetchMap) toTarget:self withObject:nil];

    [super viewDidLoad];
}

- (void)fetchMap {
    NSAutoreleasePool *threadPool = [[NSAutoreleasePool alloc] init];

    Mappe *mappa;

    mappa = [[[MapFetcher sharedInstance] fetchManagedObjectsForEntity:@"Mappe" 
                                                     withPredicate:[NSPredicate predicateWithFormat:@"Citta == %@", map] 
                                                    withDescriptor:@"Citta"] objectAtIndex:0];
    [self performSelectorOnMainThread:@selector(showImage:) withObject:mappa waitUntilDone:YES];

    [threadPool release];

}

- (void)showImage:(Mappe *)mappa {
    imvMappa = [[UIImageView alloc] initWithFrame:CGRectMake( 0.0, 0.0, 1024.0, 704.0 )];
    [imvMappa setImage:[UIImage imageWithData:[mappa Mappa]]];
    [scrollView addSubview:imvMappa];
    [scrollView setContentSize:CGSizeMake( 1024.0, 704.0 )];
    [scrollView setMinimumZoomScale:0.5];
    [scrollView setMaximumZoomScale:4.0];
    [scrollView setZoomScale:1.0];
    [scrollView setContentMode:(UIViewContentModeScaleAspectFit)];
    [scrollView setClipsToBounds:YES];
    [scrollView setDelegate:self];
    [imvMappa release];
    [loadingImage stopAnimating];
    [waitFor setHidden:YES];
    [scrollView setHidden:NO];
}

scrollView 是一个插座,Mappe 是一个托管对象,它应该可以正常工作,因为我在应用程序的任何地方都使用它并且不会造成任何麻烦。我真的被卡住了,可能导致崩溃-n-重启的原因是什么?


编辑:内存分析

我使用 Instruments - Memory Monitor 来查看发生了什么,它告诉我在启动时,我的应用程序使用 17 MB 内存,而分配显示:Live Bytes 883 KB,总共 4MB。我有点困惑......当我启动上面的代码时,我看到:2MB 的实时字节(4 个视图控制器)总共 22 MB,而内存监视器显示 77 MB 的实际内存。我应该看什么才能获得真实的情况报告?

4

1 回答 1

0

您有一个托管对象上下文,并且您将托管对象从一个线程传递到另一个线程,然后使用它。这是一个不不。相反,每个线程都应该有自己的托管对象上下文,并且 ObjectsID 在线程之间传递。接收线程然后从它自己的托管对象上下文中检索托管对象。

更多信息:http: //developer.apple.com/library/ios/#documentation/cocoa/conceptual/CoreData/Articles/cdConcurrency.html

于 2011-05-21T04:48:08.927 回答