[myArray addObject:[[objcBlock copy] autorelease]] crashes on dealloc'ing the array

时光毁灭记忆、已成空白 提交于 2019-12-04 10:33:39

Example 1:

[animations addObject:[[block copy] autorelease]];

This is copying a block, and autoreleasing the copy.

Example 2:

[animations addObject:[block copy]];
[block release];

This is copying a block, then releasing the original. If you've handled memory well, this should result in your original block being overreleased (and crashing), and your copy being leaked.

Example 3:

[animations addObject:[block copy]];
[block autorelease];

This is copying a block, then autoreleasing the original. See note with previous example.

Your answer, then, is that your code is doing something wrong elsewhere. Fix that, and go back to your first example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!