// 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,我们不是在泄漏内存吗?Apple NSURLConnection文档是否错误?
什么时候你应该释放连接并收到数据?
你在哪里发布? – 2010-08-20 22:30:07
完成加载后释放连接。无论是在连接完成加载或连接确实失败,错误。完成后释放数据。只有你可以知道你什么时候做完了。基本的内存管理原则。 – Jasarien 2010-08-20 23:32:40