Я разрабатываю приложение для iPhone. У меня есть следующий метод:
- (void)generateTokenWithUserId: (NSString *)uniqueId {
NSLog(@"TokenGenerator - generateTokenWithUserId: '%@'", uniqueId);
NSString *myMD5String = [Utilities returnMD5Hash:uniqueId];
// Create the request.
NSMutableString *authURL = [[NSMutableString alloc] initWithString:CLOUDMADE_AUTH];
[authURL appendString: localApiKey];
[authURL appendString: USER_ID];
[authURL appendString: myMD5String];
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:authURL]
cachePolicy: NSURLRequestUseProtocolCachePolicy
timeoutInterval: 60.0];
[theRequest setHTTPMethod: @"POST"];
NSLog(@"TokenGenerator URL - '%@'", authURL);
// create the connection with the request
// and start loading the data
//NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (connection) {
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
responseData = [[NSMutableData data] retain];
} else {
// Inform the user that the connection failed.
}
[authURL release];
}
Я получаю: potential leak on an object allocated on line 52 and stored into 'connection'
.
Метод Dealloc для этого класса:
- (void) dealloc {
NSLog(@"TokenGenerator - dealloc");
[responseData release];
[localApiKey release];
[super dealloc];
}
И объявление интерфейса:
@class TokenGenerator;
@protocol TokenGeneratorDelegate <NSObject>
- (void)tokenGeneratorDidFinishGeneration:(TokenGenerator *)tokenGenerator token:(NSString *)tokenGenerated;
@end
@interface TokenGenerator : NSObject {
NSString *localApiKey;
id<TokenGeneratorDelegate> delegate;
NSMutableData *responseData;
}
@property (nonatomic, assign) id<TokenGeneratorDelegate>delegate;
- (id) initWithApikey:(NSString*) apiKey delegate:(id)anObject;
- (void)generateTokenWithUserId: (NSString *)uniqueId;
@end
Как я могу исправить эту проблему? Могу ли я создать копию для этого объекта, а затем назначить ее для responseData?