title: ios cmmotionanager memory usage
body: <p>I followed this tutorial: <a href="http://blogs.captechconsulting.com/blog/john-morrison/ios-getting-started-accelerometer-data" rel="nofollow">http://blogs.captechconsulting.com/blog/john-morrison/ios-getting-started-accelerometer-data</a> 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.</p>
  
  <p>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:</p>
  
  <pre><code>[self.motionManager setDeviceMotionUpdateInterval:0.1];
  aQueue=[[NSOperationQueue alloc]init];
  [self.motionManager     startDeviceMotionUpdatesToQueue:aQueue
   withHandler:^(CMDeviceMotion *motion, NSError *error)
   {
       if (motion.userAcceleration.x &gt; movementThreshold || motion.userAcceleration.y &gt; movementThreshold || motion.userAcceleration.z &gt; movementThreshold) {
           movementCount = 5;
       };
  
       motion = nil;
   }];
  </code></pre>
  
  <p>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.</p>
  
  <p>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...</p>
  
  <p>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?...</p>