Frage

Ich habe gearbeitet Speicherlecks in meinem Programm auszuzubügeln und ich bin auf ein paar Nachzügler nach unten. Das Merkwürdige ist, dass sie kommen, wenn ich Corelocation verwenden, um eine GPS-Position zu bekommen. Der Code zurückkehrt richtig die Lage, aber es ist überall undicht: CFHTTPMessage, CFURLConnection, CFURLRequest, CFURLResponse, GeneralBlock-16, -32, -48, Httprequest, etc ... Könnte jemand bitte leite mich, wie dieses Problem beheben?

Initialisierung von MyCLController

locationController = [[MyCLController alloc] init];
locationController.delegate = self;
[locationController.locationManager startUpdatingLocation];

einige Dinge tun und einen Rückruf durch die Delegierten erhalten:

[locationController release];

MyCLController.h:

#import <Foundation/Foundation.h>
@protocol MyCLControllerDelegate 
@required
- (void)locationUpdate:(CLLocation *)location;
- (void)locationError:(NSError *)error;
@end
@interface MyCLController : NSObject  {
    CLLocationManager *locationManager;
    id delegate;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, assign) id  delegate;

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation;

- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error;
@end

MyCLController.m:

#import "MyCLController.h"
@implementation MyCLController
@synthesize locationManager;
@synthesize delegate;

- (id) init {
    self = [super init];
    if (self != nil) {
        self.locationManager = [[[CLLocationManager alloc] init] autorelease];
        self.locationManager.delegate = self; // send loc updates to myself
    }
    return self;
}

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation {
    [locationManager stopUpdatingLocation];

    [self.delegate locationUpdate:newLocation];
}

- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error {
    [self.delegate locationError:error];
}
- (void)dealloc {
    [super dealloc];
}
@end
War es hilfreich?

Lösung

Sie müssen die Locationmanager freizugeben. Stellen Sie sicher, dass Sie seine Delegaten auf NULL gesetzt vor der Freigabe. Und auch, es ist keine gute Idee, nur das erste Ergebnis zurück. Stellen Sie sicher, horizontale Genauigkeit nicht <0 und ist auch unter einem gewissen Schwellenwert, wie 5000 Meter. Und damit es robuster, können Sie einen Timer hinzufügen möchten, um es nach einer bestimmten Zeit aufhören zu machen, wenn es nicht Ihre Position genau genug finden.

Andere Tipps

Sie lösen nie locationController

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top