Утечки памяти безопасности при использовании NSURLConnection - PullRequest
1 голос
/ 06 октября 2011

Я подключаюсь к службе автозаполнения Google, используя NSURLConnection.Я продолжаю получать утечки памяти безопасности.Утечки:

   0 libsystem_c.dylib calloc
1 Security init
2 Security ltc_init_multi
3 Security ecc_ansi_x963_import_ex
4 Security ecc_ansi_x963_import
5 Security sslEcdhKeyExchange
6 Security SSLEncodeKeyExchange
7 Security SSLPrepareAndQueueMessage
8 Security SSLAdvanceHandshake
9 Security SSLProcessHandshakeRecord
10 Security SSLProcessProtocolMessage
11 Security SSLHandshakeProceed
12 Security SSLHandshake
13 CFNetwork SocketStream::_PerformSecurityHandshake_NoLock()
14 CFNetwork SocketStream::performHandshake(SocketStream::Handshake)
15 CFNetwork SocketStream::socketCallbackWriteLocked(SocketStreamSignalHolder*)
16 CFNetwork SocketStream::socketCallback(__CFSocket*, unsigned long, __CFData const*, void const*)
17 CFNetwork SocketStream::_SocketCallBack_stream(__CFSocket*, unsigned long, __CFData const*, void const*, void*)
18 CoreFoundation __CFSocketDoCallback
19 CoreFoundation __CFSocketPerformV0
20 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
21 CoreFoundation __CFRunLoopDoSources0
22 CoreFoundation __CFRunLoopRun
23 CoreFoundation CFRunLoopRunSpecific
24 CoreFoundation CFRunLoopRunInMode
25 Foundation +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:]
26 Foundation -[NSThread main]
27 Foundation __NSThread__main__
28 libsystem_c.dylib _pthread_start
29 libsystem_c.dylib thread_start

и класс, который я написал для обработки соединения:

#import "AsyncConnectionController.h"
@implementation AsyncConnectionController
@synthesize receivedData;
@synthesize connectionDelegate;
@synthesize succeededAction;
@synthesize failedAction;


- (id)initWithDelegate:(id)delegate selSucceeded:(SEL)succeeded selFailed:(SEL)failed {
    if ((self = [super init])) {
        self.connectionDelegate = delegate;
        self.succeededAction = succeeded;
        self.failedAction = failed;
    }
    return self;
}
-(void)dealloc {
[receivedData release];
[connectionDelegate release];
[super dealloc];
}
 - (BOOL)startRequestForURL:(NSURL*)url {

[url retain];

//NSURL *myURL = url;

NSMutableURLRequest* urlRequest = [[NSMutableURLRequest alloc] initWithURL:url];
// cache & policy stuff here
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPShouldHandleCookies:YES];
NSURLConnection* connectionResponse = [[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self] autorelease];
if (!connectionResponse)
{
    // handle error
    [url release];

    [urlRequest release];
    return NO;
} else {
    [self setReceivedData:[NSMutableData data]];
}

[url release];

[urlRequest release];


return YES;
}

- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response {
[receivedData setLength:0];
}
- (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data {
[receivedData appendData:data];
}
- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error {
UIAlertView *alert =
[[[UIAlertView alloc]
  initWithTitle:NSLocalizedString(@"Connection problem", nil)
  message:NSLocalizedString(@"A connection problem detected. Please check your internet connection and try again.",nil)

  delegate:self
  cancelButtonTitle:NSLocalizedString(@"OK", nil)
  otherButtonTitles:nil, nil]
 autorelease];
[alert show];

[connectionDelegate performSelector:failedAction withObject:error];
self.receivedData = nil;
}
- (void)connectionDidFinishLoading:(NSURLConnection*)connection {
[connectionDelegate performSelector:succeededAction withObject:receivedData];
self.receivedData = nil;
}
@end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...