메모리가 부족한 후 앱이 닫힙니다. Instruments의 스크린 샷
이것은 계측기를 통해 앱을 실행할 때 얻는 것입니다. 핵심 데이터를 많이 처리하고 있습니다. 나는 이것이 분명히 옳지 않다는 것을 알 수 있지만이 스크린 샷이 무엇을 말하고 있는지 정말로 알지 못합니다. 무엇이 문제인 것처럼 보입니까? 내가 조언을 (내가 위에서 편집 한) @autoreleasepools에 포장, 여기에 주어진 다음, 그것은 여전히 후 추락 :
NSFetchRequest *oldFetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *oldEntryEntity = [NSEntityDescription entityForName:@"Entry"
inManagedObjectContext:oldContext];
[oldFetchRequest setEntity:oldEntryEntity];
int numberOfEntries = [oldContext countForFetchRequest:oldFetchRequest error:nil];
int batchSize = 4;
[oldFetchRequest setFetchLimit:batchSize];
int offset = 0;
while (numberOfEntries - offset > 0) {
@autoreleasepool {
[oldFetchRequest setFetchOffset:offset];
NSError *error;
NSArray *entries = [oldContext executeFetchRequest:oldFetchRequest error:&error];
for (NSManagedObject *entry in entries) {
@autoreleasepool {
Entry *newEntry = [NSEntityDescription insertNewObjectForEntityForName:@"Entry"
inManagedObjectContext:newContext];
newEntry.entryID = [entry valueForKey:@"entryID"];
NSMutableOrderedSet *newMediaSet = [[NSMutableOrderedSet alloc] init];
NSOrderedSet *mediaSet = [entry valueForKey:@"media"];
int i = 0;
for (NSManagedObject *media in mediaSet) {
Media *newMedia = [NSEntityDescription insertNewObjectForEntityForName:@"Media"
inManagedObjectContext:newContext];
newMedia.isInPhotoLibrary = [media valueForKey:@"isInPhotoLibrary"];
newMedia.positionInEntry = [NSNumber numberWithDouble:i + 1];
MediaImageData *imageData = [NSEntityDescription insertNewObjectForEntityForName:@"MediaImageData"
inManagedObjectContext:newContext];
imageData.data = [media valueForKey:@"originalImage"];
newMedia.imageData = imageData;
newMedia.entry = newEntry;
[newMediaSet addObject:newMedia];
i++;
}
newEntry.media = newMediaSet;
}
}
[newContext save:&error];
offset = offset + batchSize;
}
}
편집 : 당신이 관심이 있다면, 코드, 응축이있다
그것은 분명 처음보다는 코드로 더 있어요,하지만 여전히 충돌하는 것이 일어났다.
중요한 코드를 제거하지 마십시오. 그러면 우리는 무슨 일이 일어나고 있는지 추측해야합니다. 가져 오기 요청이 올바르게 설정되지 않았습니다. 또한, autoreleasepool을 어디에 추가했는지는 알지 못합니다 ... 데이터베이스의 크기가 얼마나 큽니까? 미디어 세트와 미디어 세트에 포함 된 이미지의 크기는 어느 정도입니까? 어디서나 물건을 들고 있습니까? 당신은 문맥을 전혀 제거하고 있습니까? –
나는 지금 autoreleasepools를 넣었다. 미디어 세트의 이미지는 표준 이미지의 크기이며, 사진에 따라 각각 약 1MB로 추측됩니다. 위의 코드 밖에서는 아무 것도하지 않습니다. 나는 맥락을 없애지 않을거야. – Andrew