Hello list !
I have a weird behavior with NSURLConnection (still trying to have my
custom protocol to handle some HTTP GET behind the scene). So as Maciej
suggested I am investigating the used for NSURLConnection.
My custom protocol is doing (extract of the source) :
- (void) startLoading
{
myDataProvider = [DataProvider newDataProviderWithRequest:[self
request] protocol:self];
[myDataProvider startLoadingData];
}
The code in startLoadingData is then calling :
_connection = [[TSCustomConnection alloc]
initURLConnectionWithRequest:[NSURLRequest requestWithURL:url]];
[_connection startDownload];
Notice here that the retain count for _connection should be one : it's
not an autoreleased object.
And the implementation for the class TSCustomConnection is something
like :
- initURLConnectionWithRequest:(NSURLRequest *)request
{
[super init];
_request = [request retain];
_data = nil;
return self;
}
- (void) startDownload
{
_data = [[NSMutableData dataWithCapacity:4096] retain]; //
Initialize with a default size
_connection = [[NSURLConnection connectionWithRequest:_request
delegate:self] retain];
}
So in the last call the delegate for the NSURLConnection is the
TSCustomConnection which have a retain count of 1.
The connection is then calling back all the delegate method without
problem.
I am quite surprise after setting up a breakpoint in my
TSCustomConnection dealloc to see the following stack trace :
#0 -[TSCustomConnection dealloc] (self=0x2220460, _cmd=0x90870b34) at
TSURLConnection.m:25
#1 0x90a248e8 in -[NSURLConnection(NSURLConnectionInternal)
_releaseDelegate] ()
#2 0x90a0cff0 in -[NSURLConnection(NSURLConnectionInternal)
_sendCallbacks] ()
#3 0x909f76fc in -[NSArray makeObjectsPerformSelector:withObject:] ()
#4 0x90a21778 in _sendCallbacks ()
#5 0x90193ed8 in __CFRunLoopDoSources0 ()
#6 0x90191790 in __CFRunLoopRun ()
#7 0x901960bc in CFRunLoopRunSpecific ()
#8 0x909fced0 in -[NSRunLoop runMode:beforeDate:] ()
#9 0x90a159ec in -[NSRunLoop run] ()
#10 0x90a67858 in +[NSURLConnection(NSURLConnectionInternal)
_resourceLoadLoop:] ()
#11 0x90a3a198 in forkThreadForFunction ()
#12 0x900247e8 in _pthread_body ()
I was not expecting my custom connection to be deallocated in the
dealloc from my DataProvider class which retain the custom
connection... Soon after this dealloc, my application crash with
another stack trace that look similar to the one above; except I do not
know what is the reason of this failure :
(gdb) bt
#0 0x90831234 in objc_msgSend ()
#1 0x909f1c54 in NSPopAutoreleasePool ()
#2 0x909f76fc in -[NSArray makeObjectsPerformSelector:withObject:] ()
#3 0x90a21778 in _sendCallbacks ()
#4 0x90193ed8 in __CFRunLoopDoSources0 ()
#5 0x90191790 in __CFRunLoopRun ()
#6 0x901960bc in CFRunLoopRunSpecific ()
...
Any suggestion on how to avoid this problem ? Why is the
NSURLConnection releasing the delegate ??
- N.
PS: tested on Panther 7B85
_______________________________________________
webkitsdk-dev mailing list | email@hidden
Help/Unsubscribe: http://www.lists.apple.com/mailman/listinfo/webkitsdk-dev
Do not post admin requests to the list. They will be ignored.