J'ai travaillé à aplanir les fuites de mémoire dans mon programme et je suis à quelques traînards. La chose étrange est qu'ils viennent de quand j'utilise CoreLocation pour obtenir un emplacement GPS. Le code renvoie correctement l'emplacement, mais il fuit partout: CFHTTPMessage, CFURLConnection, CFURLRequest, CFURLResponse, GeneralBlock-16, -32, -48, HTTPRequest, etc ... Quelqu'un pourrait-il me guider pour résoudre ce problème?iPhone Help: Fuite de mémoire impaire dans CoreLocation Framework
Initialisation de MyCLController
locationController = [[MyCLController alloc] init];
locationController.delegate = self;
[locationController.locationManager startUpdatingLocation];
Est-ce que certaines choses et obtenir un rappel par le délégué:
[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
Ceci est utile. – JonLeah