2011-08-10 58 views
3

我有一個用戶定義的方法內聲明的數組。我使用這個數組來存儲從sqlite數據庫返回的值。然後我使用該值進行進一步處理......但Xcode在數組聲明中給了我下面的警告。 「在初始化過程中存儲的值永遠不會被讀取」 這裏是我的代碼:內存泄漏警告

NSMutableArray *tempId=[NSMutableArray array]; 
NSString *sqlStr1=[NSString stringWithFormat:@"select deck_id from decksTable limit '%d' offset '%d'",1,deckID-1]; 
char *sql1 = (char*)[sqlStr1 UTF8String]; 
tempId=[appDelegate.dbConnection fetchColumnFromTable:sql1 col:0]; 
NSNumber *tempint1 =[tempId objectAtIndex:0]; 
int actualDeckID=[tempint1 intValue]; 

請大家幫我出這一點。

注意dbConnection是數據庫連接對象,而fetchColumnFromTable是用戶定義的方法,它返回從數據庫獲取的值數組。然後我得到NSNumber中的第一個值,並將其轉換爲整數,以便在我的代碼中使用它。我在tempId數組的聲明中得到了上面的警告。

+0

可能的重複:http://stackoverflow.com/questions/2646582/clang-error-objective-c-value-stored-during-initialization-is-never-read –

回答

5

NSMutableArray *tempId=[NSMutableArray array];是沒有必要的,因爲不使用此語句分配的內存,並且您將tempId指向在tempId=[appDelegate.dbConnection fetchColumnFromTable:sql1 col:0];處返回的數組。所以基本上你可以聲明數組而不是初始化它。 NSMutableArray *tempId;

+0

非常感謝!有效! :) – booleanBoy

+0

確實不錯! –