상당히 적은 메모리 사용 공간을 유지하면서 상당히 큰 CoreData 가져 오기 (약 25,000 행)를 수행하려고합니다. 효율적인 데이터 가져 오기를 다루는 문서를 읽고 거기에 제안 된 모든 것을 구현하기 위해 노력했습니다. (내 MOC의 undoManager와 같은 설정은 무효로합니다.)CoreData 가져 오기 중 메모리 사용량이 많습니다.
아래 코드를 실행하면 내 응용 프로그램의 메모리 사용량이 여전히 약 180MB까지 올라갑니다. 완료되면 응용 프로그램은 최종 NSAutoreleasePool 드레인 호출에 관계없이 180MB 표시 부근에 있습니다.
할당을 통해 응용 프로그램을 실행하면 메모리 사용량의 95 %가 내 [self.moc save:&error]
호출에 기인 한 것으로 나타납니다. 여기서 내가 뭘 잘못하고 있니?
- (void)generateCache
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSUInteger count = 0, batchSize = 1000;
// SNIP SNIP
// Iterate over our directory structure
for(NSString *item in directoryStructure)
{
NSDictionary *info = [fm attributesOfItemAtPath:item error:nil];
FileRecord *record = (FileRecord *)[NSEntityDescription insertNewObjectForEntityForName:@"FileRecord" inManagedObjectContext:self.moc];
record.size = [NSNumber numberWithUnsignedLongLong:[info fileSize]];
record.path = item;
count ++;
if(count == batchSize)
{
NSError *error = nil;
if([self.moc save:&error])
{
NSLog(@"MOC saved down and reset");
[self.moc reset];
[pool drain];
pool = [[NSAutoreleasePool alloc] init];
count = 0;
}
}
}
// Perform any necessary last minute MOC saves
if (count != 0) {
[self.moc save:nil];
[self.moc reset];
}
// Drain our NSAutoreleasePool
[pool drain];
// Tell our main thread that we're done
if ([self respondsToSelector:@selector(completedCache)])
{
[self performSelectorOnMainThread:@selector(completedCache) withObject:nil waitUntilDone:NO];
}
}
저장으로 인해 생성 된 오류는 로깅하지 않습니까? 또한, 수입에 의해서만 사용되는 MOC입니까? –