对象没有在iPhone中发布

时间:2010-05-28 07:43:25

标签: iphone memory-leaks

我在我的代码中编写此代码以将数据存储在数据库中..

Search *objSearchDetail = [[Search alloc] init];

        objSearchDetail = [xmlResponseDetail objectAtIndex:i];

        sql = "INSERT INTO tblsearchdetail(tblrecentsearch_id,name,address,email,url,street,postcode,city,telephone,mobile) VALUES(?,?,?,?,?,?,?,?,?,?)";
        returnValue = sqlite3_prepare_v2(database, sql, -1, &insertStatement, NULL);

        if(returnValue == SQLITE_OK){
            sqlite3_bind_int(insertStatement, 1, intLastRecentSearchId);
            sqlite3_bind_text(insertStatement, 2, [objSearchDetail.strName UTF8String], -1,SQLITE_TRANSIENT);   
            sqlite3_bind_text(insertStatement, 3, [objSearchDetail.strAddress UTF8String], -1,SQLITE_TRANSIENT);    
            sqlite3_bind_text(insertStatement, 4, [objSearchDetail.strEmail UTF8String], -1,SQLITE_TRANSIENT);  
            sqlite3_bind_text(insertStatement, 5, [objSearchDetail.strUrl UTF8String], -1,SQLITE_TRANSIENT);    
            sqlite3_bind_text(insertStatement, 6, [objSearchDetail.strStreet UTF8String], -1,SQLITE_TRANSIENT); 
            sqlite3_bind_text(insertStatement, 7, [objSearchDetail.strPostCode UTF8String], -1,SQLITE_TRANSIENT);
            sqlite3_bind_text(insertStatement, 8, [objSearchDetail.strPlace UTF8String], -1,SQLITE_TRANSIENT);
            sqlite3_bind_text(insertStatement, 9, [objSearchDetail.strTelephone UTF8String], -1,SQLITE_TRANSIENT);
            sqlite3_bind_text(insertStatement, 10, [objSearchDetail.strMobile UTF8String], -1,SQLITE_TRANSIENT);
            if(sqlite3_step(insertStatement)==SQLITE_DONE)
            {
                //Data;                 
            }
        }
        NSLog(@"count %d",[objSearchDetail retainCount]);
        [objSearchDetail release];

现在nslog显示引用计数为2,所以即使我发布引用计数仍然是1,并且对象不会被销毁。 请帮助我......

1 个答案:

答案 0 :(得分:2)

因为你从数组中获取objSearchDetail的值,所以既不应该分配它,也不应该释放它。 只是做:

Search *objSearchDetail = [xmlResponseDetail objectAtIndex:i];

并删除

[objSearchDetail release];