0

我按照本教程: http: //blogs.captechconsulting.com/blog/john-morrison/ios-getting-started-accelerometer-data让我的 iPhone 应用程序监听加速度计。在我的 AppDelegate 中添加了 CMMotionManager,并添加了一个属性来读取视图控制器中应用程序的 CMMotionManager。现在我在我的应用程序上收到内存使用警告。

我将应用程序连接到内存分析器仪器,并且可以看到当我不与应用程序交互并且它静止地坐在桌子上时,我的内存使用量呈线性增长。罪魁祸首似乎在这段代码中:

[self.motionManager setDeviceMotionUpdateInterval:0.1];
aQueue=[[NSOperationQueue alloc]init];
[self.motionManager     startDeviceMotionUpdatesToQueue:aQueue
 withHandler:^(CMDeviceMotion *motion, NSError *error)
 {
     if (motion.userAcceleration.x > movementThreshold || motion.userAcceleration.y > movementThreshold || motion.userAcceleration.z > movementThreshold) {
         movementCount = 5;
     };

     motion = nil;
 }];

第一个示例内联定义了队列,作为最后的手段,我将队列移到了我的视图控制器的成员变量中——似乎都没有太大的效果。当我不打开更新间隔时,我看不到内存使用量增加。当我打开更新间隔时,内存会增长。

motionCount 被声明为 viewController 的私有 int,并用于跟踪最近的手机移动。随着时间的推移,另一个线程慢慢地将计数器重置为零......但是启用/禁用该线程似乎不会影响内存使用,所以我已经离开了那个代码......

我在网络上没有看到任何关于 CMMotionManager 可能导致内存使用过多的警告,但是在我让应用程序运行的每一分钟,都会消耗另外 5 兆内存......有什么技巧可以帮助了解我的问题?...

4

1 回答 1

1

看起来我在看错误的列(截图)-应该使用“Live Bytes”,但正在查看“Overall Bytes”......我生命中有六个小时我没有回来......

于 2013-06-21T22:32:11.513 回答