开发者

Memory Leak 'Select Statement' iPhone

开发者 https://www.devze.com 2023-02-15 02:10 出处:网络
Hi after several hours searching i have found the function which gives me memory leaks. The leaks i get are:

Hi after several hours searching i have found the function which gives me memory leaks. The leaks i get are:

Leaked Object#AddressSize   Responsible L开发者_开发技巧ibrary Responsible Frame
NSCFString  2   < multiple >    32  Foundation  
-[NSPlaceholderString initWithBytes:length:encoding:]

i cant see anything wrong with this code. any help would be gratefully received Dan

  -(void)readItems {


    if (!database) return; // earlier problems
    // build select statement
    if (!selStmt)
    {
        const char *sql = "SELECT * FROM Demotivate order by name asc;";
        if (sqlite3_prepare_v2(database, sql, -1, &selStmt, NULL) != SQLITE_OK)
        {

            selStmt = nil;


        }
    }
    if (!selStmt)
    {
        NSAssert1(0, @"Can't build SQL to read items [%s]", sqlite3_errmsg(database));
    }

    // loop reading items from list
    [items removeAllObjects]; // clear list for rebuild
    int ret;
    while ((ret=sqlite3_step(selStmt))==SQLITE_ROW) 
    { // get the fields from the record set and assign to item
        // primary key
        NSInteger n = sqlite3_column_int(selStmt, 0); 
        Item *item = [[Item alloc] initWithPrimaryKey:n]; // create item
        // item name
        char *s = (char *)sqlite3_column_text(selStmt, 1);
        if (s==NULL) s = "";
        item.name = [NSString stringWithUTF8String:(char *)s];
        // quantity needed
        item.howOften = sqlite3_column_int(selStmt, 3);
        // noted
        s = (char *)sqlite3_column_text(selStmt, 2);
        if (s==NULL) s = "";
        item.Cost = [NSString stringWithUTF8String:(char *)s];
        s = (char *)sqlite3_column_text(selStmt, 4);
        if (s==NULL) s = "";
        item.income = [NSString stringWithUTF8String:(char *)s];
        s = (char *)sqlite3_column_text(selStmt, 5);
        if (s==NULL) s = "";
        item.wage = [NSString stringWithUTF8String:(char *)s];

        [items addObject:item]; // add to list
        [item release]; 
        // free item
    }
    sqlite3_reset(selStmt); // reset (unbind) statement


}


Probably you forgot to release item.name in Item's dealloc.

0

精彩评论

暂无评论...
验证码 换一张
取 消