1

リレーションシップ内のエンティティにアクセスすると、(私にとっては) 奇妙なメモリ リークが発生します。

シリーズとタイルは互いに逆の関係にあります。

// 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!

Instruments は、最終行に 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 の最初の部分にコピーしましたが、まだリークしています。私のモデルに何か問題があるのでしょうか?

4

2 に答える 2

1

NSPlaceHolder は、次のような構造で NSSrting のメモリの割り当てを延期するために、基盤ライブラリによって使用される「シングルトン」* です。

[[NSString alloc] initWithString:@"only know the size of this string in the init, not the alloc"];

1 つだけ* 漏れた場合、それは実際には漏れではありません。

  • 「シングルトン」と「1」と言いますが、複数の NSPlaceHolderStrings が存在する可能性があります。allocWithZone が使用されている場合は、NSZone ごとに 1 つです。
于 2010-05-19T05:29:17.490 に答える
0

リリースしavailableSeriesますか?それ以外には何も見えません。

于 2010-05-18T15:52:36.980 に答える