【发布时间】:2011-04-01 21:41:36
【问题描述】:
// Create the request.
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
receivedData = [[NSMutableData data] retain];
} else {
// Inform the user that the connection failed.
}
既然我们没有通过调用retain来“拥有”receivedData,我们不是在泄漏内存吗?
如果有的话,你应该什么时候释放连接和接收数据?
【问题讨论】:
标签: iphone objective-c cocoa-touch memory nsurlconnection