1

私は物事のクラッシュログを取得しています:

2011-07-21 23:18:51.233 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fbdef0 of class NSURL autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.233 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x1462e38 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.233 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x1462e38 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.233 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fb32b0 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.235 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fc04e0 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.235 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5f98960 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.235 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fa9c70 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.550 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fbfbb0 of class NSHTTPURLResponse autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.550 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fb5840 of class __NSCFData autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.550 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fb1400 of class __NSArrayM autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.551 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5f83e70 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.551 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fbd480 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.551 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fb31b0 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.551 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fa9aa0 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.551 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fa6110 of class __NSArrayI autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.552 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fb9700 of class NSCFString autoreleased with no pool in place - just leaking

クラッシュを回避するのに役立つボディはありますか?

4

3 に答える 3

3

自動解放プールのないスレッドでコードを実行しているため、これが表示されている可能性があります。自動リリースプールはAppleのすべてのAPIで頻繁に使用されるため、スレッド全体をラップすることが重要です。この例は次のようになります。

- (void)myThreadMethod:(id)anObject {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSLog(@"This is some objective-c code...");
    [pool drain];
}

[プールドレン]の部分は非常に重要です。そのコードスニペットがないと、スレッドの存続期間中に自動リリースされたすべてのオブジェクトがリークされます。

于 2011-07-21T18:29:50.817 に答える
1

Apple のドキュメントリンクから:

NSAutoreleasePool クラスは、Cocoa の参照カウント メモリ管理システムをサポートするために使用されます。自動解放プールには、プール自体が空になったときに解放メッセージが送信されるオブジェクトが格納されます。

重要: 自動参照カウント (ARC) を使用する場合、自動解放プールを直接使用することはできません。代わりに、@autoreleasepool ブロッ​​クを使用します。たとえば、次の代わりに:

 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
// Code benefitting from a local autorelease pool. 
[pool release];

あなたは書くでしょう:

 @autoreleasepool {
     // Code benefitting from a local autorelease pool. 
}

@autoreleasepool ブロッ​​クは、NSAutoreleasePool のインスタンスを直接使用するよりも効率的です。ARC を使用しない場合でも使用できます。

于 2014-08-07T16:03:07.037 に答える
1

のインスタンスをセットアップしますNSAutoreleasePool。詳細と例については、NSAutoreleasePool クラス リファレンスを参照してください。

また、メモリ管理プログラミング ガイドをざっと読んで、これを設定することが重要な理由とautorelease実際の動作を確認することもできます。

また、この投稿のディスカッションも役に立ちました: NSAutoreleasePool autorelease プールはどのように機能しますか?

于 2011-07-21T18:24:07.593 に答える