Re: A newly alloc] init]ed NSURLConnection has retainCount = 3 ??
Re: A newly alloc] init]ed NSURLConnection has retainCount = 3 ??
- Subject: Re: A newly alloc] init]ed NSURLConnection has retainCount = 3 ??
- From: John Stiles <email@hidden>
- Date: Mon, 25 Jul 2005 15:22:48 -0700
You are not supposed to rely on the retain count for anything. You can
query it as a debugging aid, but you should never assume that all the
retains on any object are /your/ retains.
Sorry, but those are the rules of the game. You just need to write your
code ensuring that for every retain, there is a balancing release; if
you do this, it will all work out in the end :) (And if it doesn't,
it's not your bug!)
Jerry Krinock wrote:
When I -alloc] init] an NSURLConnection, the result has a retain count of 3
instead of 1. This makes it makes it really confusing later when I want to
get rid of it. Please someone explain this to me before I do too much
reverse-engineering! Log output from Demo program:
A new NSString has retainCount = 1
A new NSURLConnection has retainCount = 3
which was made by executing the following tool:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString* string = [[NSString alloc]
initWithString:@"http://www.apple.com"] ;
NSLog(@"A new NSString has retainCount = %i", [string retainCount]) ;
NSURL *url = [NSURL URLWithString:string];
NSURLRequest* theRequest=[NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:60.0];
NSObject* aDelegate = [[NSObject alloc] init] ;
NSURLConnection* connection = [[NSURLConnection alloc]
initWithRequest:theRequest delegate:aDelegate];
NSLog(@"A new NSURLConnection has retainCount = %i", [connection
retainCount]) ;
[pool release];
return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden