0

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?...

jkrebsbach
  • 105
  • 7
  • The tutorial has CMMotionManager declared in app delegate, but for grins I moved the alloc into the view controller where most of the tutorials have it. - When I moved the allocation into the view controller, the memory "leak" went away... Now the memory usage appears much more stable... But don't I want to use one common CMMotionManager? Wouldn't that be better?... *grumble* – jkrebsbach Jun 21 '13 at 02:32

1 Answers1

1

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...

jkrebsbach
  • 105
  • 7
  • I think I realized the problem - I was looking at the wrong column in the instrument panel. Column one says "Overall Bytes" - which I assumed was the total consumption of the application. Apparently that column is the number of bytes the application has used during the lifespan of the app, but not the number being currently used. The column I should have been looking at is the second column - "Live Bytes" - this is the column that shows how many bytes are actually being used. Overall Bytes never goes down, but Live Bytes goes up and down. I don't know why I couldn't see that until now... – jkrebsbach Jun 21 '13 at 23:18