开发者

Objective-c when to release objects

开发者 https://www.devze.com 2022-12-25 19:36 出处:网络
-(IBAction)registerUpdate:(id)开发者_StackOverflowsender { HTTPRequest* request = [[HTTPRequest alloc] initWithUrl:@\"http://www.yahoo.com\" delegate:self];
-(IBAction)registerUpdate:(id)开发者_StackOverflowsender {
    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?


You release it with autorelease

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

精彩评论

暂无评论...
验证码 换一张
取 消