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

  • Home
  • SEARCH
  • 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 103765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:10:32+00:00 2026-05-11T01:10:32+00:00

When retrieving objects from an NSMutableArray in cocoa-touch is the below code ok? Should

  • 0

When retrieving objects from an NSMutableArray in cocoa-touch is the below code ok? Should I be allocating([alloc]) new Page objects each time or is just pointing to it alright? Do I need to do anything to the Page *pageObj after, such as set it to nil?

const char *sql = 'insert into Page(Book_ID, Page_Num, Page_Text) Values(?, ?, ?)'; for (i = 0; i < ([[self pagesArray] count] - 1); i++) {     if(addStmt == nil) {         if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK) {             NSAssert1(0, @'Error while creating add statement. '%s'', sqlite3_errmsg(database));         }     }     Page *pageObj = [[self pagesArray] objectAtIndex:i];     if(pageObj.isNew) {         sqlite3_bind_int(addStmt, 1, self.book_ID);          sqlite3_bind_int(addStmt, 2, pageObj.page_Number);           sqlite3_bind_text(addStmt, 3, [[pageObj page_Text] UTF8String], -1, SQLITE_TRANSIENT);         if(SQLITE_DONE != sqlite3_step(addStmt)) {             NSAssert1(0, @'Error while inserting data. '%s'', sqlite3_errmsg(database));         }         NSLog(@'Inserted Page: %i into DB. Page text: %@', pageObj.page_Number, pageObj.page_Text);     }     //Reset the add statement.     sqlite3_reset(addStmt);                      } 

Thanks. I also understand this should probably be in a transaction but I didn’t quite get that working just yet.

  • 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. 2026-05-11T01:10:32+00:00Added an answer on May 11, 2026 at 1:10 am

    The way you’re declaring a pointer is correct. You don’t need alloc, since that creates a new object, when you want to refer to an existing object in the array. You would want to retain it if you were going to keep the reference outside of that method, but since you’re only using it temporarily it’s fine not to.

    The actual pointer variable will be destroyed and recreated every trip to the loop, so there’s no need to set it to nil. Even if you declared the variable outside the loop, simply assigning it to a new object is fine. The only time you’d set it to nil is when you’re releasing the object stored in the pointer (or the object may be released elsewhere). If you didn’t set it to nil in that case, the pointer would refer to an invalid memory location after the object is dealloced, usually causing a crash.

    One bug I can see though, you’re skipping the last element in your array in your for loop by subtracting 1 from the count.

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

Sidebar

Ask A Question

Stats

  • Questions 66k
  • Answers 66k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Unfortnately, Windows Media Services doesn't seem to stream FLVs: A… May 11, 2026 at 11:37 am
  • added an answer After giving a straight answer to your question, I'd like… May 11, 2026 at 11:37 am
  • added an answer You'll want to end up with a query that looks… May 11, 2026 at 11:37 am

Related Questions

When retrieving objects from an NSMutableArray in cocoa-touch is the below code ok? Should
When retrieving a lookup code value from a table, some folks do this... Dim
When retrieving values from a DataRow is it better to use the column name
Are there performance issues when retrieving and filtering data from views than from tables
I've encountered a problem when retrieving a JSONP response from a server in a
We have a problem with the Euro character when saving and retrieving it from
How would you go about retrieving the @@IDENTITY value for each row when the
When editing XAML in VS2008 SP1, the editor is really slow. devenv process seems
When should I include PDB files for a production release? Should I use the
When using jQuery 's ajax method to submit form data, what is the best

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.