iPad Application Crash Causes Reboot memory problems?
I have an application on iPad that crashes causing the reboot. This crash happens somewhere after the method 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 is an outlet, Mappe is a managed object and it should works fine because I use it everywhere in the app and it causes no troubles. I'm really stuck, what can be that can causes crash-n-reboot?
EDIT: Memory Analyzing
I've used Instruments - Memory Monitor to see what's going on, and it tells that at the moment of launch, my app开发者_JS百科lication uses 17 MB of memory, while the allocation says: Live Bytes 883 KB, overall 4MB. I'm a bit confused... When I launch the code above I see: 2MB of Live Bytes (4 ViewControllers) Overall 22 MB, while Memory Monitor says 77 MB of real memory. What should I see to have a real report of the situation?
You have one managed object context and you're passing managed object from one thread to another and then using it. This a no no. Instead, each thread should have its own managed object context and ObjectsIDs are passed between threads. Receiving thread then retrieves managed object from its own managed object context.
More info: http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/CoreData/Articles/cdConcurrency.html
精彩评论