2011-05-12 5 views
0

나는 objective-c에서 메모리 관리가 시작되었다고 생각했지만 나는 세트를 추가하는 것으로부터 얻는 보유 수에 대해 조금 혼란스러워했다. setByAddingObjectsFromSet에 대한 API는 말한다 :NSSet setByAddingObjectsFromSet 보유 수

NSSet* tom = [[NSMutableSet alloc] initWithCapacity:1]; 
NSSet* dick = [[NSMutableSet alloc] initWithCapacity:1]; 
NSSet* harry = [tom setByAddingObjectsFromSet:dick]; 

printf("tom retainCount: %d \n", [tom retainCount]); 
printf("dick retainCount: %d \n", [dick retainCount]); 
printf("harry retainCount: %d \n", [harry retainCount]); 

생산 :

tom retainCount: 1 
dick retainCount: 1 
harry retainCount: 2 

setByAddingObjectsFromSet이 새로운 세트를 돌려주는 경우는 왜 retainCount입니다

Returns a new set formed by adding the objects in a given set to the receiving set. 

- (NSSet *)setByAddingObjectsFromSet:(NSSet *)other 

그래서 나는이 당황 조금 있어요 2? 나는 그것을 두 번 공개해야합니까?! 나는 무엇을 잘못 이해 했는가?

고맙습니다.

+4

는 사용하지 마십시오 retainCount : http://stackoverflow.com/questions/5784084/calling-retaincount-considered-harmful –

+1

참조 : [1 ] (http://stackoverflow.com/questions/5155559/weird-behaviour-with-retaincount) [2] (http://stackoverflow.com/questions/5233143/retaincount-in-blocks-show-extrange-behavior) [3] (http://stackoverflow.com/questions/5483357/nsstring-retaincount-is-2147483647) [4] (http://stackoverflow.com/questions/5391479/why-is-the-retaincount-still- 1 - 개체 - 릴리스 후) [5] (http://stackoverflow.com/questions/3354724/dont-worry-about-retaincount-really) [6] (http://stackoverflow.com/questions/5220902/) [...] (http://stackoverflow.com/search?page=3&tab=relevance&q=retaincount) –

답변

2

전혀 출시 할 필요가 없습니다. 사실 으로 출시하지 않아야합니다. 당신은 그것을 소유하지 않습니다. 그 유품은 코코아 출신이며, 코코아는 그것을 처리해야 할 책임이 있습니다. 귀하의 우려가 아닙니다. (이 retainCount 보는 것은 권할 왜 많은 이유 중 하나입니다.)