2011-08-10 135 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

确实不错! –