开发者

memory management in objective-c for retain

开发者 https://www.devze.com 2023-01-27 18:09 出处:网络
HI i have questions on Memory 开发者_如何学PythonManagement If I alloc object1 time then i retain 2 time And then release 4 time&

HI i have questions on Memory 开发者_如何学PythonManagement If I alloc object 1 time then i retain 2 time And then release 4 time & then retain 1 time for same object. what will be my final ans?


Crrrrraaassshh!


The object will be dealloced after the third release (when the retainCount hits zero) and the fourth release will be sent to a non-valid object, resulting in a crash.

If you want an object to exist for a little while after you've released it, you should look into the autorelease method.

0

精彩评论

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