在访问关系中的实体时,我有一个奇怪的(对我来说)内存泄漏。
系列和瓷砖彼此之间存在反比关系。
// set up the fetch request
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Series" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
// grab all of the series in the core data store
NSError *error = nil;
availableSeries = [[NSArray alloc] initWithArray:[managedObjectContext executeFetchRequest:fetchRequest error:&error]];
[fetchRequest release];
// grab one of the series
Series *currentSeries = [availableSeries objectAtIndex:1];
// load all of the tiles attached to the series through the relationship
NSArray *myTiles = [currentSeries.tile allObjects]; // 16 byte leak here!
仪器报告说最后一行由NSPlaceHolderString导致16字节泄漏。
堆栈追踪:
2 UIKit UIApplicationMain
3 UIKit -[UIApplication _run]
4 CoreFoundation CFRunLoopRunInMode
5 CoreFoundation CFRunLoopRunSpecific
6 GraphicsServices PurpleEventCallback
7 UIKit _UIApplicationHandleEvent
8 UIKit -[UIApplication sendEvent:]
9 UIKit -[UIApplication handleEvent:withNewEvent:]
10 UIKit -[UIApplication _runWithURL:sourceBundleID:]
11 UIKit -[UIApplication _performInitializationWithURL:sourceBundleID:]
12 Memory -[AppDelegate_Phone application:didFinishLaunchingWithOptions:] /Users/cfish/svnrepo/Memory/src/Memory/iPhone/AppDelegate_Phone.m:49
13 UIKit -[UIViewController view]
14 Memory -[HomeScreenController_Phone viewDidLoad] /Users/cfish/svnrepo/Memory/src/Memory/iPhone/HomeScreenController_Phone.m:58
15 CoreData -[_NSFaultingMutableSet allObjects]
16 CoreData -[_NSFaultingMutableSet willRead]
17 CoreData -[NSFaultHandler retainedFulfillAggregateFaultForObject:andRelationship:withContext:]
18 CoreData -[NSSQLCore retainedRelationshipDataWithSourceID:forRelationship:withContext:]
19 CoreData -[NSSQLCore newFetchedPKsForSourceID:andRelationship:]
20 CoreData -[NSSQLCore rawSQLTextForToManyFaultStatement:stripBindVariables:swapEKPK:]
21 Foundation +[NSString stringWithFormat:]
22 Foundation -[NSPlaceholderString initWithFormat:locale:arguments:]
23 CoreFoundation _CFStringCreateWithFormatAndArgumentsAux
24 CoreFoundation _CFStringAppendFormatAndArgumentsAux
25 Foundation _NSDescriptionWithLocaleFunc
26 CoreFoundation -[NSObject respondsToSelector:]
27 libobjc.A.dylib class_respondsToSelector
28 libobjc.A.dylib lookUpMethod
29 libobjc.A.dylib _cache_addForwardEntry
30 libobjc.A.dylib _malloc_internal
我想我错过了一些明显的东西,但我无法弄清楚是什么。
感谢您的帮助!
更新:我已经将有问题的代码块复制到applicationDidFinishLaunching的第一部分,但它仍然存在泄漏。我的模型可能有问题吗?
答案 0 :(得分:1)
NSPlaceHolder是基础库使用的'singleton'*,用于推迟在以下构造中分配NSSrting的内存:
[[NSString alloc] initWithString:@"only know the size of this string in the init, not the alloc"];
如果你只泄漏一个*,那真的不是泄漏。
答案 1 :(得分:0)
你发布availableSeries
吗?除此之外,我什么也没看到。