2010-11-28 4 views
0

사용자 지정 LocationDetail 개체로 채울 NSMutableArray * cityData가 있습니다. cityData는 viewDidLoad에서 만들어지고 dealloc에서 릴리스됩니다. 사용자의 동작에 따라 코드의 어딘가에, 내가 LocationDetail을 채우고 cityData 배열에 추가 : 유틸리티 내가 코드에서 누수가 말한다NSString을 사용한 메모리 관리 문제

내가보기 컨트롤러 완료하고 그것을 제거하고
LocationDetail* d = [[LocationDetail alloc] init]; 
    d.city = [NSString stringWithFormat:@"%S", (char*)sqlite3_column_text16(statement, 1)]; 
    d.tz = [NSString stringWithFormat:@"%S", (char*)sqlite3_column_text16(statement, 3)]; 
    d.country = [NSString stringWithFormat:@"%S", (char*)sqlite3_column_text16(statement, 2)]; 
    d._id = [NSString stringWithFormat:@"%S", (char*)sqlite3_column_text16(statement, 0)]; 

    [cityData addObject:d]; 
    [d release]; 

, 누출 위의 [NSString stringWithFormat]과 함께 네 줄의 NSCFString에서 위의 내용을 확인하십시오.

은 내가 sqlite3를 물건을 제거 시도와 같은 결과

d._id = [NSString stringWithFormat:@"%s", "a string"] 

같은 것을 호출을 단순화. 그러나 NSString stringWithFormat을 다음과 같이 바꾸면

d._id = @"a string"; 

누수가 사라집니다. stringWithFormat을 사용하면 누수가 왜 생기는 지 궁금하지만 @ "something"을 사용하면 안됩니다. 내가 잘못하고 있다는 것이 명백한가요?

감사합니다.

+0

LocationDetail에 대한 각'@ 속성 '('city','tz','country' 및'_id')을 어떻게 정의했는지 보여주세요. –

+0

LocationDetail의 속성은 모두 NSStrings *이고 그 길을 정의했습니다 : @property nonatomic, 보유) NSString * _id; – MirekE

+0

@interface LocationDetail : NSObject { NSString * city; NSString * tz; NSString * 국가; \t NSString * _id; } @property (비 원자력, 보유) NSString * 도시; @property (비 원자력, 보유) NSString * tz; @property (비 원자력, 보유) NSString * 국가; @property (비 원자력, 보유) NSString * _id; @end – MirekE

답변

1

속성이 자동으로 해제되지 않은, 당신은 자신의

- (void)dealloc 

는 예를 들어 The Objective-C Programming Language: Declared Properties를 참조 것을 할 필요가있다.


편집 :

그것은 예는 Advanced Memory Management Programming Guide로 이동 한 것으로 보인다.

+0

예, 놓쳤습니다. 감사! – MirekE

+0

불행히도 그 링크가 깨졌습니다. – Ant

+0

공지를 보내 주셔서 감사합니다. 게시물을 최신 링크로 업데이트했습니다. –