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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:12:40+00:00 2026-05-25T15:12:40+00:00

I have this big doubt: I have my function in a class like this:

  • 0

I have this big doubt:
I have my function in a class like this:

-(Shot*) getShot:(int)shot {
    NSString *sqlStr = [NSString stringWithFormat:@"SELECT * FROM tbShots where nShot = %d ", shot];
    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *documentFolderPath = [searchPaths objectAtIndex:0];
    NSString *dbFilePath = [documentFolderPath stringByAppendingPathComponent:DATABASE_NAME_EXT];

    if (dbFilePath == NULL) {
        NSLog(@"dbFilePath is NULL");
    }

    sqlite3 *dbHandle;
    if (sqlite3_open([dbFilePath UTF8String], &dbHandle)) {
        NSLog(@"sqlite3_open: failed");
    }

    sqlite3_stmt *preparedStatement;
    const char* queryStatement = [sqlStr UTF8String];
    sqlite3_prepare_v2(dbHandle, queryStatement, -1, &preparedStatement, NULL);

    Shot *s = nil;
    NSString * note = @"";
    while( sqlite3_step(preparedStatement) == SQLITE_ROW)
    {
        s = [[Shot alloc] initWithShot:shot];
    }

    sqlite3_finalize(preparedStatement);
    sqlite3_close(dbHandle);    
    return s;
}

and outside this class I use this:

  Shot* sP = [appDelegate getShot:nTarget];
  [self drawShoot:sP];

but I think that is not the right method to retrieve an instance of an object and use it…
what’s the best way???
also after the use of the instance sP, I need to release? if I release the operation affect also the appDelegate class?

thanks

  • 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-25T15:12:41+00:00Added an answer on May 25, 2026 at 3:12 pm

    s = [[Shot alloc] initWithShot:shot];
    make it autoreleased object to [[[Shot alloc] initWithShot:shot] autorelease]; and then your method returns autoreleased object.
    Shot* sP = [appDelegate getShot:nTarget];
    [self drawShoot:sP];
    should be fine then. otherwise you are left with retain count 1 on Shot object “s” when your return s; in your method.

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

Sidebar

Related Questions

I have multiple setTimeout functions like this: function bigtomedium(visiblespan) { visiblespan.removeClass('big').addClass('medium'); setTimeout(function(){ mediumtosmall(visiblespan);},150); };
I have this big function (1300+ lines of code) that takes data from the
Here's the deal. I have a big class hierarchy and I have this one
I have a table that looks something like this: word big expensive smart fast
I have this big function that gets a lot of different data and insert
I have this big object that I'd like to fadeOut and its not working
I'm aware that questions like this have been asked before and I doubt it's
I am thinking that this is big problem .... I have path like this...C:\restore\restoredb\
I have this big data-entry sort of page, a table kind of layout using
so I have this HTML table with a bunch of big numbers in it

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.