Value stored to 'recordView' during its initialization is never read

本文通过具体案例解析了使用Instruments进行代码静态分析的过程及意义,指出了一种常见的内存使用不当的问题,并给出了修正建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用instruments做代码的静态分析时:

第一行的分析结果是:Value stored to 'recordView' during its initialization is never read

JoinRecordHeaderView *recordView = [tableViewdequeueReusableHeaderFooterViewWithIdentifier:@"JoinRecordHeaderView"];

recordView = [[[NSBundlemainBundle] loadNibNamed:@"JoinRecordHeaderView"owner:selfoptions:nil]firstObject];

recordView.date =_joinSectionHeaderTitleAry[section -3];


有点诧异,什么叫“recordView存储的值在初始化过程中不会被读取”!

后来发现原来是没重用好,正确的代码应该是:

JoinRecordHeaderView *recordView = [tableViewdequeueReusableHeaderFooterViewWithIdentifier:@"JoinRecordHeaderView"];

if (!recordView) {

   recordView = [[[NSBundlemainBundle] loadNibNamed:@"JoinRecordHeaderView"owner:selfoptions:nil]firstObject];

   recordView.date =_joinSectionHeaderTitleAry[section -3];

}

如果不用instruments分析,真不敢想象写出这么丢人的代码!

回到主题上来,没重用好,导致每次都重新加载并重新初始化recordView,导致instruments有这样的分析结果,这样的结果都能分析出来,instruments真是厉害的工具。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值