アプリがありnon-gc OS X
ます。このアプリでは、ブロック内からブロック変数にオブジェクトを代入しようとしています。このオブジェクトは、別のスレッドによって配列からクリーンアップされています。構造体がフラグを設定していて、dispose ヘルパー関数がオブジェクトをクリーンアップしているのはnon-gc
アプリだからだと思います。コピーは十分に安全な修正ですか?block_byref
BLOCK_NEEDS_FREE
- (void)assignFromArray
{
__block NSObject iWantToKeep = nil;
[myArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
{
if([[obj stringVar] isEqualToString:MyStringConst])
{
iWantToKeep = [obj copy];
*stop = YES;
}
}];
/* Assume here that the array has been cleaned up by another thread
* and all the objects in it have been released.
*
* Was a copy safe enough to survive the block_byref dispose
* and the array objects being dealloc'd so that it can be accessed here?
*/
NSLog(@"%@", [iWantToKeep stringVar]);
//I only need it briefly, so it can be cleaned up here
[iWantToKeep autorelease];
}