How use object after release?
foo declarat开发者_StackOverflow中文版ion in h. file
I do [foo release] operation
Next i need use foo second time. How?
You cannot reuse an object after it has been deallocated.
You must simply not release it until after the second operation is complete.
As stated before, you cannot use objects after they have been deallocated. Deallocation occurs when their retainCount
goes to zero. If, for some reason, you cannot remove that [foo release]
call, you must call [foo retain]
beforehand. You can also try to call [foo autorelease]
instead of [foo release]
, if your second usage is shortly after.
There is a very good walkthrough for memory management in Objective-C here: Stanford's cs193p Lecture 4
精彩评论