jkrebsbach
jkrebsbach

Reputation: 107

ios cmmotionanager memory usage

I followed this tutorial: http://blogs.captechconsulting.com/blog/john-morrison/ios-getting-started-accelerometer-data to get my iPhone app to listen to the accelerometer. Added the CMMotionManager to my AppDelegate, and added a property to read the CMMotionManager for the application in the viewcontroller. Now I'm getting memory usage warnings on my app.

I hooked the app up to the memory profiler instrument, and can see that my memory usage to grows linearly when I am not interacting with the application and it is stationary sitting on the table. The culprit appears to be in this code:

[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;
 }];

The first examples had the queue defined inline, as a last resort I moved the queue to being a member variable of my view controller - neither seems to have much effect. When I do not turn on the update interval I do not see memory usage grow. When I turn on the update interval, memory grows.

movementCount is declared as a private int for the viewController, and is being used to track recent phone movement. Another thread slowly resets the counter back down to zero over time... But enabling/disabling that thread doesn't seem to impact memory usage so I've left that code out...

I don't see anything on the web warning that the CMMotionManager can cause excessive memory usage, but for every minute I leave my app running, another 5 megs of memory is consumed... Are there any tricks to help get to the bottom of my problem?...

Upvotes: 0

Views: 359

Answers (1)

jkrebsbach
jkrebsbach

Reputation: 107

Looks like I was looking at the wrong column (screenshot) - should have been using "Live Bytes" but was looking at "Overall Bytes"... There goes six hours of my life I'm not getting back...

Upvotes: 1

Related Questions