Note that there are some explanatory texts on larger screens.

plurals
  1. POCLLocationManager - strange Memory Leak
    primarykey
    data
    text
    <p>I'm implementing a CLLocationManager right as described in several tutorials.</p> <p>Everything works fine up to the point where the LocationManager receives a second update. Then a memory leak occurs. </p> <p>Instruments tells me, that the leaked objects are NSCFTimer, GeneralBlock-16 and NSCFSet</p> <p>Any ideas?</p> <p>Thanks for any help</p> <p>[Edit]</p> <p>After repeatingly starting and stopping the locationManager, the updated seem to come faster. This makes me think that the CLLocationManager initializes a new timer every time a location-update occurs... VERY strange...</p> <p>And - so you don't need to read my comment - the app crashes after a while</p> <p>[Edit]</p> <p>Ok - I don't get it here's some code...</p> <p>I'm using a separate class for the locationManager, as described here: <a href="http://www.vellios.com/2010/08/16/core-location-gps-tutorial/" rel="nofollow noreferrer">http://www.vellios.com/2010/08/16/core-location-gps-tutorial/</a></p> <p>locationManager.h</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import &lt;CoreLocation/CoreLocation.h&gt; @protocol locationManagerDelegate @required - (void)locationUpdate:(CLLocation *)location; - (void)locationError:(NSError *)error; @end @interface locationManager : NSObject &lt;CLLocationManagerDelegate&gt;{ CLLocationManager *myLocationManager; id delegate; CLLocation *bestEffortAtLocation; BOOL outOfRange; } @property (nonatomic, retain) CLLocationManager *myLocationManager; @property (nonatomic, retain) CLLocation *bestEffortAtLocation; @property (nonatomic, assign) id delegate; @property (nonatomic, assign) BOOL outOfRange; @end </code></pre> <p>locationManager.m</p> <pre><code>#import "locationManager.h" @implementation locationManager @synthesize myLocationManager; @synthesize delegate; @synthesize bestEffortAtLocation; @synthesize outOfRange; - (id) init { self = [super init]; NSLog(@"initializing CLLocationManager"); if (self != nil) { outOfRange = NO; self.myLocationManager = [[[CLLocationManager alloc] init] autorelease]; self.myLocationManager.delegate = self; self.myLocationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; [self performSelector:@selector(stopUpdatingLocation:) withObject:@"Timed Out" afterDelay:100.0]; }else{ NSLog(@"Location Manager could not be initialized"); } return self; } - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { if(outOfRange == NO){ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(stopUpdatingLocation:) object:nil]; NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow]; if (locationAge &gt; 5.0) return; // test that the horizontal accuracy does not indicate an invalid measurement if (newLocation.horizontalAccuracy &lt; 0) return; [self.delegate locationUpdate:newLocation]; }else{ [self.myLocationManager stopUpdatingLocation]; } } - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ NSLog(@"error!!!!"); [self.myLocationManager stopUpdatingLocation]; [self.delegate locationError:error]; } - (void)dealloc { [myLocationManager release]; [bestEffortAtLocation release]; [super dealloc]; } @end </code></pre> <p>then, in the main-class I call:</p> <p>mainFile.h (exerpt)</p> <pre><code>#import "locationManager.h" @interface mainFile : UIViewController &lt;locationManagerDelegate , UIAlertViewDelegate&gt;{ locationManager *locationController; CLLocation *myLocation; } @end </code></pre> <p>mainFile.m (exerpt)</p> <pre><code>#import "locationManager.h" @implementation mainFile @synthesize locationController; @synthesize myLocation; - (void)locationError:(NSError *)error{ // Do alert-Stuff } - (void)locationUpdate:(CLLocation *)location { // Do location-Stuff } - (void)viewDidLoad { [super viewDidLoad]; locationController = [[[locationManager alloc] init] autorelease]; locationController.delegate = self; [locationController.myLocationManager startUpdatingLocation]; } - (void)dealloc { self.locationController = nil; [locationController release]; } @end </code></pre> <p>It's driving me kinda crazy :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload