2010-05-19 3 views
0

다음 코드로 인해 iPhone 응용 프로그램에서 메모리 누수가 발생하는 이유는 무엇입니까?중첩 배열을 사용하여 메모리 누수를 일으키는 합성 배열 설정

배열, 문자열 및 숫자를 포함하여 누수 된 모든 initted 개체가 누수됩니다. 그래서,이 코드 조각이 호출 된 두 번째 및 후속 시간에 속성을 다시 설정할 때 개체를 해제하지 합성 된 배열 속성과 관련이 있다고 생각 해요. 여기

코드입니다 :

"컨트롤러"(아래) 나는에 대한 참조가 내 사용자 정의보기 컨트롤러 클래스이며,이 코드 스 니펫 (snippet)로 설정하고있다 :

sqlite3_stmt *statement; 
NSMutableArray *foo_IDs = [[NSMutableArray alloc] init]; 
NSMutableArray *foo_Names = [[NSMutableArray alloc] init]; 
NSMutableArray *foo_IDsBySection = [[NSMutableArray alloc] init]; 
NSMutableArray *foo_NamesBySection = [[NSMutableArray alloc] init]; 

// Get data: 
NSString *sql = @"select distinct p.foo_ID, p.foo_Name from foo as p "; 
if (sqlite3_prepare_v2(...) == SQLITE_OK) { 
    while (sqlite3_step(statement) == SQLITE_ROW) { 
     int p_id; 
     NSString *foo_Name; 

     p_id = sqlite3_column_int(statement, 0); 
     char *str2 = (char *)sqlite3_column_text(statement, 1); 
     foo_Name = [NSString stringWithCString:str2]; 

     [foo_IDs addObject:[NSNumber numberWithInt:p_id]]; 
     [foo_Names addObject:foo_Name]; 
    } 
    sqlite3_finalize(statement); 
} 

// Pass the array itself into another array: 
// (normally there is more than one array in each array) 
[foo_IDsBySection addObject: foo_IDs]; 
[foo_NamesBySection addObject: foo_Names]; 

[foo_IDs release]; 
[foo_Names release]; 

// Set some synthesized properties (of type NSArray, nonatomic, 
// retain) in controller: 
controller.foo_IDsBySection = foo_IDsBySection; 
controller.foo_NamesBySection = foo_NamesBySection; 

[foo_IDsBySection release]; 
[foo_NamesBySection release]; 

감사합니다 어떤 도움이라도!

+0

누출을 어떻게 감지합니까? – fbrereto

+0

누출 기기를 통해. 그것이 누출을 잘못보고 있는지 궁금해지기 시작했습니다. 어쨌든, 나는 dealloc proc에서 릴리즈를 놓쳤다. 감사. – Webtoad

답변

1

빠른 검사를 통해 코드가 올바르게 표시됩니다.

컨트롤러 클래스의 dealloc을 보여줍니다. 물건을 어디에서 풀어주고 있니?

+0

그게 전부 였어. dealloc에서 속성 릴리스를 잊어 버렸습니다. 나는 너무 많은 것들을 시도해 보았습니다. 감사! – Webtoad

관련 문제