1

I use ARC. I find the memory increase constantly.

in .h file

@property (weak, nonatomic) IBOutlet UILabel* contentALabel;
@property (weak, nonatomic) IBOutlet UILabel* contentBLabel;

in .m file

-(void)refreshContent:(NSInteger) itemID
{
    sqlite3 *database;

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docsPath = [paths objectAtIndex:0];
    NSString* databasePath = [docsPath stringByAppendingPathComponent: @"Database.sqlite"];
    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {

        NSString  *sql = [NSString stringWithFormat:@"select contentA,contentB from tableA where  itemID = %d ",itemID,nil];

        char *sqlStatement = (char *)[sql cStringUsingEncoding:NSASCIIStringEncoding];
        sqlite3_stmt *compiledStatement;

        if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {

            while(sqlite3_step(compiledStatement) == SQLITE_ROW) {

                NSString *contentA = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
                NSString *contentB = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];

                contentALabel.text = contentA;
                contentBLabel.text = contentB;
            }
        }

        sqlite3_finalize(compiledStatement);
    }
    sqlite3_close(database);
}

I call this function constantly , I find my memory increase as well in the 'Profile' window 'Living Bytes' column.

but if I comment

contentALabel.text = contentA;
contentBLabel.text = contentB;

the memory won't increase any more.

What's wrong with the 'Label.text' ?

Rob
  • 415,655
  • 72
  • 787
  • 1,044
lostin2010
  • 123
  • 2
  • 10
  • There's no problem with `label.text` except that it maintains a strong reference to your `NSString` (but it should release the previous value when you set the new value). Are you possibly creating new `contentALabel` and `contentBLabel` objects, without doing `removeFromSuperview` on the old ones? – Rob Jan 12 '13 at 18:24
  • I encountered the same problem. described here: http://stackoverflow.com/questions/16495240/if-uilabel-text-different-chinese-strings-memory-leak – Vergil Lu May 11 '13 at 08:58
  • Did your content contains multibytes characters? – Vergil Lu May 11 '13 at 09:04

1 Answers1

0

Bottom line, setting the text property for a UILabel would not explain this behavior. I'd be inclined to run through the battery of suggestions covered here. Specifically, look for leaks and if you don't find any, use the allocations tool to identify what's being created (and obviously not released). I'd also put in a breakpoint and then type "po [[UIWindow keyWindow] recursiveDescription]" into the debugger and make sure you're not getting additional views/controls added to your window hierarchy.

I know this isn't going to feel like a satisfactory answer, but you're just going to have to spend a little time in Instruments, looking for leaks, and if not apparent, just identifying the allocations that are obviously not getting released.

Community
  • 1
  • 1
Rob
  • 415,655
  • 72
  • 787
  • 1,044