views:

51

answers:

2

my iphone application has lots of buttons (i created a calendar view with buttons) when i run it with Leaks tool - no leaks are discovered. But somehow Allocation Live Bytes reaches 21MB and application crashes (when buttons are clicked for about 120 times).

doesn't system autorelease memory not being used anymore... if there are no leaks how come memory keeps on increasing? any ideas on how to approach this problem will be appreciated. thanks.

i am using sqlite3 in my application to load (calendar - values stores against 30 days at a time)- which calls function getSingRecord 30 times... below is the actual code

-(void) insertRecordIntoTableNamed:
{

NSString *sql="Insert Statement......";

char *err;

if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, &err) != SQLITE_OK) {
    sqlite3_close(db);
    NSAssert(0,@"Error updating table");
}

}

-(NSString *) getSingRecord: (NSString *) getStatement{

NSString *sql=getStatement;

sqlite3_stmt *statement;

NSString *fieldFlagI=@"0";

if (sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil) == SQLITE_OK) {
    while (sqlite3_step(statement) == SQLITE_ROW) {
        char *fieldFlag=(char *) sqlite3_column_text(statement, 0);
        fieldFlagI=[[NSString alloc] initWithUTF8String:fieldFlag];
        //fieldFlagI=[NSString initWithUTF8String:fieldFlag];
    }
    sqlite3_finalize(statement);
}
//NSString *ffI=fieldFlagI;
//[fieldFlagI release]
return [fieldFlagI autorelease];
} 
+1  A: 

You most probably are relying on an autorelease pool which is never being drained. Since the pool exists and keeps your objects retained, the tools don't detect this as a memory leak. And if you never drain the pool, all the objects you allocated are kept alive even after you're done with them.

Franci Penov
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];...my code.....[pool drain];still didn't even make the slightest difference
A: 

Leaks are objects that no one is referencing, but that are not released. If you are keeping objects in an datastructure and holding onto them, that's not going to be seen as a leak, but it is a problem. What do you do on the button press?

UPDATE: Based on your code

Don't autorelease the return -- you don't always alloc it (initialized to @"0"), autorelease only if you alloc it.

But that's not your leak.

In the while(), every time you loop, you leak the last one you alloc'd -- does your get statement definitely return one row? If so, why a while()?

Lou Franco
i am using sqlite3 commands to get rows
sqlite3 is pure-C -- are you calling all of their cleanup functions when you are supposed to?
Lou Franco
NSString *sql=[NSString stringWithFormat:@"Insert or replace into '%@' ('%@','%@','%@') values ('%@','%@','%@')", tableName,field1,field2,field3,field1Value,field2Value,field3Value]; char *err; if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, NSAssert(0,@"Error updating table"); }for insert i am using above code
NSString *sql=getStatement; sqlite3_stmt *statement; NSString *fieldFlagI=@"0"; if (sqlite3_prepare_v2(db, [sql UTF8String], -1, fieldFlagI=[[NSString alloc] initWithUTF8String:fieldFlag]; //fieldFlagI=[NSString initWithUTF8String:fieldFlag]; } sqlite3_finalize(statement); } //NSString *ffI=fieldFlagI; //[fieldFlagI release] return [fieldFlagI autorelease];for select above statements
update your question so the code formats.
Lou Franco