Objective-c何时释放对象

时间:2010-04-03 21:14:47

标签: objective-c memory-management

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

HTTPRequest发出异步请求并调用当前类中的onHTTPResponse方法。

我的问题是我必须发布请求吗?我的猜测是我应该把它变成一个实例变量?

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

我如何释放该字符串对象,还是应该将其分配给变量?

1 个答案:

答案 0 :(得分:1)

您使用autorelease

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