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 4251952
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:43:50+00:00 2026-05-21T04:43:50+00:00

Hi All I have a class that works with sqlite database in my application.

  • 0

Hi All I have a class that works with sqlite database in my application. Here you can see one of the functions that I have write. This function must get the count of items in witch the column value is equals to the given value.

 + (int) GetCountOfItems: (NSString*) byColumn {
        // Autorelease Pool.
        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc]init];
        // Create Sqlite query string.
        NSString* sqliteQuery = [NSString stringWithFormat:@"SELECT COUNT(*) FROM [Articles] WHERE %@ = 1", byColumn];
        NSLog(@"GetCountOfItems query string is: %@", sqliteQuery);
        // Create statement.
        sqlite3_stmt*   stmt;
        int articleCount = 0;

        if( sqlite3_prepare_v2(database, [sqliteQuery UTF8String], -1, &stmt, NULL) == SQLITE_OK ) {
            if( sqlite3_step(stmt) == SQLITE_ROW )
                articleCount  = sqlite3_column_int(stmt, 0); 
        }
        else NSLog(@"Failed from GetCountOfItems. Error is:  %c", sqlite3_errmsg(database));

        // Finalize.
        sqlite3_finalize(stmt);

        // Release Pool.
        [pool release];

        return articleCount;
    }

I want to know if this function is correct for example should i use NSAutoreleasePool* pool = [[NSAutoreleasePool alloc]init]; ???? And how it can help me with memory ?

  • 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-21T04:43:50+00:00Added an answer on May 21, 2026 at 4:43 am

    Based on the following description (in the Memory Management Programming Guide):

    The Application Kit automatically creates a pool at the beginning of an event cycle (or event-loop iteration), such as a mouse down event, and drains it at the end, so your code normally does not have to worry about them. There are three cases, though, where you might use your own autorelease pools:

    If you are writing a program that is not based on the Application Kit, such as a command-line tool, there is no built-in support for autorelease pools; you must create them yourself.

    If you spawn a secondary thread, you must create your own autorelease pool as soon as the thread begins executing; otherwise, you will leak objects. (See “Autorelease Pools and Threads” for details.)

    If you write a loop that creates many temporary objects, you may create an autorelease pool inside the loop to dispose of those objects before the next iteration. This can help reduce the maximum memory footprint of the application.

    I’d say don’t bother, just allocate any objects as required, then release them before returning from the method.

    Also, see this post.

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

Sidebar

Related Questions

I have a windows form application that uses a Shared class to house all
I have a class that creates several IDisposable objects, all of these objects are
I have a class file that contains all the classes that are needed for
I have a java class that applies an xslt to all xml files in
I have multiple classes that all derive from a base class, now some of
I have a class library with all my database logic. My DAL/BLL. I have
I have implemented VirtualPathProvider class so I can keep all my views in the
I am creating a linq-to-sql model with EF, and have a class that works
Let's say I have some class X that is going to be injected all
I have an I18n helper class that can find out the available Locale s

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.