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? 나는 그것을 두 번 공개해야합니까?! 나는 무엇을 잘못 이해 했는가?
고맙습니다.
는 사용하지 마십시오 retainCount : http://stackoverflow.com/questions/5784084/calling-retaincount-considered-harmful –
참조 : [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) –