0

が実際にどのように機能するかについての詳細なアップルのドキュメントは見つかりませんNSZombie。実際にはオブジェクトを解放せず、余分な解放をキャッチするために参照の数を維持するように設計されていることを理解していますが、次のようなものはどのように機能しますか:

for(int i = 1; i < 10; i++)
{
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity: i];

[array release];

}

NSZombie同じ変数/オブジェクトが同じアプリケーションで割り当て/初期化され、解放されているため、これを技術的にどのように処理しますか? すべてallocrelease.

4

2 に答える 2

1

ゾンビでは、オブジェクトを実際に解放する必要はありません[1] -- オブジェクトの保持カウントが 0 に達した後のある時点で、オブジェクトは単純に「ゾンビ」に変わります。「ゾンビ化」インスタンスにメッセージを送信すると、特別なエラーが発生します。ハンドラが実行されます。

1) ゾンビの解放はオプションです。長時間実行するタスクやメモリを集中的に使用するタスクのためにメモリが本当に必要でない限り、ゾンビを解放しないNSDeallocateZombies方が効果的なテストです ( = NO)

于 2012-08-26T22:07:18.040 に答える
0

この質問は、Brad Larsonのコメントで回答されました。

見積もり:

That isn't the same object, or the same memory. You're creating a distinct, new NSMutableArray instance on every pass through that loop. Just because a pointer to each is assigned to array does not make them the same object.

A pointer merely points to a particular location in memory where the object exists. A given object in memory can have multiple pointers to it, or even none (when it is being leaked). NSZombie acts on the object itself, not pointers to it.

于 2012-08-26T22:02:17.147 に答える