Objective-C를 완전히 처음 접했고 언제 객체를 할당하고 해제해야하는지 알아 내려고했습니다.할당 할 필요가 있는지, 배포해야하는지 어떻게 알 수 있습니까?
예를 들어 웹에서 일부 데이터를 가져 오려고합니다.
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];
내가 이해하지 못하는 것은 : 왜 그들은 연결이 아니라 요청에 ALLOC를 호출해야 할이 코드를 가지고있는 애플에 an article 발견? 할당이 필요한 시점과 그렇지 않은 시점을 어떻게 알 수 있습니까?
릴리스와 유사한 질문입니다. 내가 읽은 것부터, alloc/init을 사용하여 초기화 된 객체 만 릴리스해야합니다. 그러나 모든 "initWithXXX"함수는 대신 자동 렌더링 된 객체를 반환합니다.
이것은 어려운 규칙입니까, 아니면 규칙적인 것입니까? 객체를 릴리스해야하는지 여부를 찾는 방법이 있습니까?
비슷한 질문이 이미 있습니다. 예 : http://stackoverflow.com/questions/2379800/what-objects-do-i-alloc-release –