NSArray 内存泄漏!无法获取为什么?
您好,我在 Instruments 中遇到以下代码行内存泄漏。
NSArray *itemsList=[[NSArray alloc] initWithObjects:@"Love",
@"Hate",@"Happy",@"Sad",
@"Desire",@"Anger",@"Hope",@"Fear",@"Silly",nil];
我正在使用下面的代码: arrayList 也在 dealloc 块中释放。
NSArray *itemsList=[[NSArray alloc] initWithObjects:@"Love",@"Hate",
@"Happy",@"Sad",@"Desire",
@"Anger",@"Hope",@"Fear",@"Silly",nil];
self.arrayList=itemsList;
[itemsList release];
Hi I am getting memory leak in Instruments for the following line of code .
NSArray *itemsList=[[NSArray alloc] initWithObjects:@"Love",
@"Hate",@"Happy",@"Sad",
@"Desire",@"Anger",@"Hope",@"Fear",@"Silly",nil];
I am using the below code:
arrayList is also released in dealloc block.
NSArray *itemsList=[[NSArray alloc] initWithObjects:@"Love",@"Hate",
@"Happy",@"Sad",@"Desire",
@"Anger",@"Hope",@"Fear",@"Silly",nil];
self.arrayList=itemsList;
[itemsList release];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设
arrayList
是在@property
语句中使用retain
声明的。如果没有,那肯定是你的问题。如果是,那么您就有泄漏,但不是在您发布的代码中。重要的是要认识到,Instruments 首先显示的不一定是泄漏发生的位置,而是泄漏内存的分配位置。您将查看 arrayList 的其余用法,并找到缺少发布的保留的位置。
如果单击 Instruments 中对象内存地址旁边的箭头,您应该能够看到对象被保留和释放的所有位置。您将仔细查看它们并确定哪个保留缺少发布。
I'm assuming that
arrayList
is declared usingretain
in the@property
statement. If not, then that is certainly your problem.If it is, then you have a leak, but not in the code you've posted. It's important to realize that Instruments first shows not necessarily where the leak occurred, but where the leaked memory was allocated. You'll have look through the rest of your uses of arrayList and find where you have a retain that's missing a release.
If you click on the arrow next to the memory address of the object in Instruments, you should be able to see everywhere that your object was retained and released. You'll have look through them and identify which retain is missing a release.