This Memory Management Tip Could Save You Hours of Frustration!

原文地址:http://howtomakeiphoneapps.com/2009/04/this-memory-management-tip-could-save-your-hours-of-frustration/

 

 

Dealing with memory on the iPhone is one of the most difficult
challenges that you will face as a new iPhone developer. Today,
I am going to show you a very simple tip that will help you
debug the memory problems that you are likely to face.

One thing that you have to worry about with memory management is
the “retain count” of an object. The retain count is how the
system keeps track of the memory used by an object. If an
object’s retain count is zero and your attempt to access it
your app will crash; if you do not make sure the retain
count of your object is 0 when the object goes out of focus you
will have a memory leak.

Clearly, it is important to be able to find out what the current
retain count of an object is. Here is how you can do this:

NSLog([NSString stringWithFormat:@"Retain Count:%i", [someObject retainCount]]);

This writes out the current retain count to the log. The
important function is [someObject retainCount].

That is it - know how to find out the retain count of a particular object will give you some help in the fight against randomly crashing (or leaky) apps.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值