Chris
Chris

Reputation: 1008

Objective-c when to release objects

-(IBAction)registerUpdate:(id)sender {
    HTTPRequest* request = [[HTTPRequest alloc] initWithUrl:@"http://www.yahoo.com" delegate:self];
    [request doRequest];
}

The HTTPRequest makes an asynchronous request and calls the onHTTPResponse method in the current class.

My question is do I have to release request? My guess is that I'm supposed to make it an instance variable?

[NSString stringWithFormat:@"Data received: %@", [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]];

How would I release that string object, or should I assign it to a variable?

Upvotes: 1

Views: 118

Answers (1)

psychotik
psychotik

Reputation: 39029

You release it with autorelease

[NSString stringWithFormat:@"Data received: %@", [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease]]

Upvotes: 1

Related Questions