经常碰到 EXC_BAD_ACCESS 调试程序十分麻烦,只好回头看书
Here are the rules:
■ When you create an object using new, alloc, or copy, the object has a retain count
of 1. You are responsible for sending the object a release or autorelease message
when you’re done with it. That way, it gets cleaned up when its useful life is over.
■ When you get hold of an object via any other mechanism, assume it has a retain
count of 1 and that it has already been autoreleased. You don’t need to do any fur-
ther work to make sure it gets cleaned up. If you’re going to hang on to the object for
any length of time, retain it and make sure to release it when you’re done.
■ If you retain an object, you need to (eventually) release or autorelease it. Balance
these retains and releases.
本文介绍了如何通过正确管理Objective-C对象的引用计数来避免EXC_BAD_ACCESS错误。包括使用new、alloc或copy创建的对象应适当释放,通过其他方式获取的对象视为已自动释放,并需在长时间持有对象时保留并最终释放。
16

被折叠的 条评论
为什么被折叠?



