Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7039307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:46:57+00:00 2026-05-28T01:46:57+00:00

I have an application that uses data queries and displays them in a UITableView.

  • 0

I have an application that uses data queries and displays them in a UITableView. So far so good, I can access the SQLite database and display the data in the table but after a short period of use of my app memory Received a notice of warning. Level = 1 and closed. Using analysis tools in the search I noticed that my app data consumes a reasonable amount of memory.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  {

    tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

    return [count count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  {

    iMapDadosClientes *dadosClientes = (iMapDadosClientes *)[count objectAtIndex:indexPath.row];

    NSString *myIdent = @"myIdent";

    iMapGrid *grid = (iMapGrid *)[tableView dequeueReusableCellWithIdentifier:myIdent];

    tvDadosClientes.autoresizesSubviews = YES;

    if (grid == nil) {

        grid = [[[iMapGrid alloc] initWithFrame:CGRectZero reuseIdentifier:myIdent] autorelease];

        UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0, 50.0, tableView.rowHeight)] autorelease];

        [grid addColumn:60];

        label.tag = TAG_1; 
        label.font = [UIFont systemFontOfSize:14.0]; 
        label.text = dadosClientes.cod;
        label.textAlignment = UITextAlignmentRight; 
        label.textColor = [UIColor blackColor]; 
        label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight; 

        [grid.contentView addSubview:label]; 

        label =  [[[UILabel alloc] initWithFrame:CGRectMake(70.0, 0, 20.0, tableView.rowHeight)] autorelease]; 

        [grid addColumn:100];

        label.tag = TAG_2; 
        label.font = [UIFont systemFontOfSize:14.0]; 
        label.text = dadosClientes.loja;
        label.textAlignment = UITextAlignmentCenter; 
        label.textColor = [UIColor blackColor]; 
        label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight; 

        [grid.contentView addSubview:label]; 

        label =  [[[UILabel alloc] initWithFrame:CGRectMake(110.0, 0, 350.0, tableView.rowHeight)] autorelease]; 

        [grid addColumn:470];

        label.tag = TAG_3; 
        label.font = [UIFont systemFontOfSize:14.0]; 
        label.text = dadosClientes.nome;
        label.textAlignment = UITextAlignmentLeft; 
        label.textColor = [UIColor blackColor]; 
        label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight; 

        [grid.contentView addSubview:label]; 

        label =  [[[UILabel alloc] initWithFrame:CGRectMake(480.0, 0, 240.0, tableView.rowHeight)] autorelease]; 

        [grid addColumn:730];

        label.tag = TAG_4; 
        label.font = [UIFont systemFontOfSize:14.0]; 
        label.text = dadosClientes.mun;
        label.textAlignment = UITextAlignmentLeft; 
        label.textColor = [UIColor blackColor]; 
        label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight; 

        [grid.contentView addSubview:label]; 

        label =  [[[UILabel alloc] initWithFrame:CGRectMake(740.0, 0, 20.0, tableView.rowHeight)] autorelease]; 

        [grid addColumn:768];

        label.tag = TAG_5; 
        label.font = [UIFont systemFontOfSize:14.0]; 
        label.text = dadosClientes.est;
        label.textAlignment = UITextAlignmentCenter; 
        label.textColor = [UIColor blackColor]; 
        label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight; 

        [grid.contentView addSubview:label]; 
    }

    UILabel *label_1 = (UILabel *)[grid.contentView viewWithTag:TAG_1];
    label_1.text = dadosClientes.cod;

    UILabel *label_2 = (UILabel *)[grid.contentView viewWithTag:TAG_2];
    label_2.text = dadosClientes.loja;

    UILabel *label_3 = (UILabel *)[grid.contentView viewWithTag:TAG_3];
    label_3.text = dadosClientes.nome;

    UILabel *label_4 = (UILabel *)[grid.contentView viewWithTag:TAG_4];
    label_4.text = dadosClientes.mun;

    UILabel *label_5 = (UILabel *)[grid.contentView viewWithTag:TAG_5];
    label_5.text = dadosClientes.est;

    return grid;
}

- (void) getInitialDataToDisplay:(NSString *)dbPath {

    count = [[NSMutableArray alloc] init];

    if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {

        const char *sql = "select cod, loja, nome, mun, est from apsa1010;";
        sqlite3_stmt *selectstmt;

        if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {

            while(sqlite3_step(selectstmt) == SQLITE_ROW) {

                iMapDadosClientes *dadosClientes = [[iMapDadosClientes alloc] cod:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 0)] loja:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)] nome:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)] pessoa:nil ender:nil bairro:nil mun:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)] est:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 4)] tel:nil bco1:nil risco:nil classe:nil lc:nil transp:nil ultCom:nil statCli:nil metr:nil salDup:nil uligTlv:nil dCompra:nil vend:nil celul:nil fax:nil email:nil contato:nil dtCada:nil priCom:nil dtNac:nil dtFunda:nil recno:nil];

                [count addObject:dadosClientes];

                [dadosClientes release];



                dadosClientes = nil;
            }
        }

        sqlite3_finalize(selectstmt);
    }
    else
        sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
}

- (void) finalizeStatements {

    if(database)
        sqlite3_close(database);
}

someone give me a hint of what I might be doing wrong in my code. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:46:57+00:00Added an answer on May 28, 2026 at 1:46 am

    Not sure if these are your memory issues but here’s some things to look at.

    Always check the return codes of all sqlite calls. For example, sqlite3_finalize has a return code as does sqlite3_close. If finalize doesn’t succeed (for example, busy), you may need to cleanup in close (it doesn’t do it for you necessarily). Here’s my close function:

    if (_sqlite3)
    {   
        int rc = sqlite3_close(_sqlite3);
    
        if (rc == SQLITE_BUSY) 
        {   
            sqlite3_stmt *stmt; 
            while ((stmt = sqlite3_next_stmt(_sqlite3, 0x00)) != 0) 
            {
                sqlite3_finalize(stmt); 
            }
    
            rc = sqlite3_close(_sqlite3);
        }
    
        if (rc != SQLITE_OK)
        {
            NSLog(@"close not OK.  rc=%d", rc);
        }
    
        _sqlite3 = NULL;
    }
    

    Outside of the memory issues you should look at:

    • prepare compiles the sql statement can gives you back a reference (&selectstmt in your case). You shouldn’t recompile it every time. Instead, stuff away the reference and call sqlite3_reset before you use it again and don’t finalize until you clean up that area of the code. That allows you to use the same compiled statement over and over from the VBL – memory should hold steady.

    • Why open and close every time? This isn’t sql server client or something with a connection pool. Leave it open, re-use your compiled statements and benefit from the caches and compiled statements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have application that uses direct data access to it's Database. I have nothing
I have a Dynamic Data Entities Web Application that uses a database with GUIDs
I have a desktop (winforms) application that uses a Firebird database as a data
I have an application that uses Entity Framework to access the data, and throughout
I have an iPhone application that uses a sqlite3 database for saving data and
I have an application that uses a UITableView to present data that I have
I have an application that uses Core Data that has a relationship that I
I have client application that uses WCF service to insert some data to backend
I have a winform application that uses some referenced web services to get data.
We have a WinForms application that uses SQL server to store its data. To

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.