Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: NSURLConnection not delegate friendly (release problem)?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSURLConnection not delegate friendly (release problem)?



On Nov 11, 2003, at 18:29, Trufsoft wrote:

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.

[snip]

And the implementation for the class TSCustomConnection is something
like :
- initURLConnectionWithRequest:(NSURLRequest *)request
{
     [super init];
     _request = [request retain];
     _data = nil;
     return self;
}

I don't know if this is causing your problems, but this init method is not correct. In any init method where you call super, you should write code like this:


- initBlahBlah....
{
	if((self = [super init])) // can be initWithWhatever...
	{
		...assign ivars...
	}
	return self;
}

There are variations on this theme, but the important part is that you always assign self to the return value of [super init] and you always check it. It's completely possible that [super init] will release self and return another object instead, or simply return nil to indicate failure of some sort.

99% of the time, init returns the same thing you called it on, and so this could very well not be causing any trouble, but it's still good practice to follow for that other 1%.

--
"Hello," he lied.
		-- Don Carpenter quoting a Hollywood agent

Mike Ash - <http://www.mikeash.com/>, <mailto:email@hidden>
_______________________________________________
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.

References: 
 >NSURLConnection not delegate friendly (release problem)? (From: Trufsoft <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.