【发布时间】:2014-03-30 20:38:52
【问题描述】:
在我的 iphone 应用程序中,当发送一些数据包时,应用程序在有更多数据包时崩溃,并且它会在 xcode 上发出警报,说由于内存压力而终止应用程序。在我的代码中的几个地方,我在 for 循环中分配了一些对象并将这些分配的对象添加到队列中,所以在添加之后我想在 for 循环中释放这些对象,因为它启用了 ARC 的项目 我无法释放它,我的问题是在这种情况下会有帮助吗?而不是释放它,如果我们将这些对象设置为 nil,它会释放内存(我知道 nil 不会减少保留计数)设置 nil 是否有助于减少内存使用?
说我的代码有点像下面的例子
NSMutableArray* arrObj = [[NSMutableArray alloc]init];
for(i=0; i<=count;i++)
{
ClassA * Obja = [[classA alloc]initwithdata:xx];
ClassB * Objb = [[classB alloc]initwithdata:xx];
ClassC * Objc = [[classC alloc]initwithdata:xx];
[arrObj addObject:obja]; // Since its ARC we cant release obja will obja=nil this help?
[arrObj addObject:objb]; // Since its ARC we cant release objb will objb=nil this help?
[arrObj addObject:objc]; // Since its ARC we cant release objc will objc=nil this help?
}
【问题讨论】:
-
xx 代表什么?是图像数据吗?
-
你为什么要分配 ClassA * Obja = [[classA alloc]initwithdata:xx];在循环中?
-
使用instruments:Allocations 准确查看哪些对象会增加您的内存占用。
-
XX 在这里是一些字典,我在循环中分配它
标签: ios iphone objective-c memory-management automatic-ref-counting