开发者

Can I early-release an autorelease object?

i.e. would cause the object to 开发者_开发知识库be released immediately and not have to be released by the pool if I did this?

[[NSArray arrayWithCapacity:100] release];

Can't find a clear explanation in the docs about this.


It would likely crash when the object would normally be autoreleased. autorelease means "delayed release", so it will be released: just later. Since the object won't exist later as you are manually releasing it, you will likely crash due to the runtime sending the -release message to your now-deallocated object.

Edit: Note that if you -retain objects that come autoreleased, you do have to -release them: you are taking ownership.


I realise that this is stupid now, and that I shouldn't be releasing something I don't own.


If you don't want the object to go into the auto-release pool, you can do a manual alloc and initWithCapabity. If you do that, you'll have to manually release it at some point.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜