[英]iOS ARC memory increase constantly
Here is my code. 这是我的代码。 Memory has been constantly increasing,when the
viewDidLoad
method is called.I guess that local variable data
is not released.But why? 当调用
viewDidLoad
方法时,内存一直在不断增加。我想本地变量data
没有释放。但是为什么呢?
- (void)viewDidLoad {
[super viewDidLoad];
NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"wakeup.pcm" ofType:nil]];
NSMutableData *mData = [NSMutableData dataWithData:data];
int readLength = 0;
while (readLength < mData.length) {
if (mData.length - readLength > EVERBUFFERLEN) {
NSData *data = [mData subdataWithRange:NSMakeRange(readLength, EVERBUFFERLEN)];
readLength += EVERBUFFERLEN;
data = nil;
}
}
Such a "overall memory meter" does not really help finding leaks. 这样的“总体内存计”并不能真正帮助发现泄漏。 I. e.
即 it can be that
-dataWithContentsOfFile:
requests memory down from the system, but it is not freed after usage. 可能是
-dataWithContentsOfFile:
向系统请求内存-dataWithContentsOfFile:
,但使用后不会释放。 Reasons for that can be that allocating memory from the system is slow and holding unused memory "for the app" can be a cheaper way as long as the memory pressure isn't high. 原因可能是,只要内存压力不高,从系统分配内存的速度很慢,并且“为应用程序”保留未使用的内存可能是一种更便宜的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.