我一直在努力解决程序中的内存泄漏问题,并且我只是为了解决一些碎片问题。奇怪的是,他们来自我使用CoreLocation获取gps位置。代码正确地返回位置,但它泄漏到各地:CFHTTPMessage,CFURLConnection,CFURLRequest,CFURLResponse,GeneralBlock-16,-32,-48,HTTPRequest等...任何人都可以请指导我如何解决这个问题?iPhone Help:CoreLocation框架中的奇怪内存泄漏
的MyCLController
locationController = [[MyCLController alloc] init];
locationController.delegate = self;
[locationController.locationManager startUpdatingLocation];
初始化做一些事情,并得到一个回调通过委托:
[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
这很有用。 – JonLeah 2010-07-20 14:40:58