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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:12:59+00:00 2026-05-20T05:12:59+00:00

Just a quick question really: I’m running a method to pull records from an

  • 0

Just a quick question really:

I’m running a method to pull records from an sqlite database into an array, then assigning the contents of that array to an instance variable.

@interface {
NSArray *items;
}

@implementation
// The population method.
-(void)populateInstanceVariable
{
    NSMutableArray *itemsFromDatabase = [[NSMutableArray alloc] init];        

    // Sqlite code here, instantiating a model class, assigning values to the instance variables, and adding this to the itemsFromDatabase Array.


    self.items = itemsFromDatabase;
    [itemsFromDatabase release];

}
// viewDidLoad is calling the method above
-(void)viewDidLoad
{
    [self populateInstanceVariable];
    [super viewDidLoad];
}

// TableViewDataSource method - cellforIndexPath
- (UITableViewCell *)tableView:(UITableView *)passedInTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault];

    // Load in my model from the instance variable - ***1
    MyDataModel *model = [items objectAtIndexPath:indexPath.row];

    // Assign the title to the cell from the model data
    cell.textLabel.text = model.title;

    // This is the part i'm stuck on, releasing here causes a crash!
    [model release];

    return cell;

}

@end

My question is two fold:

  1. Is what i’m doing to assign data to the instance variable right? and am i managing the memory correctly?
  2. How do i manage the memory for that model item in the tableview datasource? the only way i seem to be able to get it to run smoothly is if i don’t release the *model object at all, but that causes leaks surely?

Cheers.

  • 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-20T05:12:59+00:00Added an answer on May 20, 2026 at 5:12 am

    No, you’re not managing memory correctly here:

    • you should use “reusable” UITableViewCells, most UITableView examples show how to do this, and

    • do not do [model release], you do not “own” the object in this case, you’re just referring to it so you must not release it

    Here’s the typical cellForRowAtIndexPath:

    -(UITableViewCell *) tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *CellIdentifier = @"CellIdentifier";
    
        // Dequeue or create a cell of the appropriate type.
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) 
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
            // settings that do not change with every row
            cell.selectionStyle = UITableViewCellSelectionStyleGray;
        }
        // settings that change with every row
        cell.textLabel.text = @"fill in your label here";
        return cell;
    }
    

    Also, if you’re using a DB for your data, you may want to look in to Core Data, Apple’s data persistence/management framework, it includes the ability to hook aspects of your data entities directly up to UITableViews.

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

Sidebar

Related Questions

I just have a quick question. I am running through an array of images
Just a quick database design question: Do you ALWAYS use an ID field in
I am using EF4. Just a quick question, is this a really good framework?
Just a quick query really, In my PHP file, I have variables coming from
just a quick question: I am a CS undergrad and have only had experience
just a quick question, if I have a matrix has n rows and m
I am working with a huge list of URL's. Just a quick question I
Just a quick question. I suppose I could just try it but I like
Hey just a quick question for any experts out there. I have a site
I have a quick question about fetching results from a weakly typed cursor and

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.