cocoa 内存管理笔记

经常碰到 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.

你可能感兴趣的:(cocoa,Access,UP)