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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:30:10+00:00 2026-06-02T05:30:10+00:00

Working on an iPhone app where I have a class instance that is defined

  • 0

Working on an iPhone app where I have a class instance that is defined as a global and initialized in in ViewDidLoad for a UITableViewController.

When it gets to cellForRowAtIndexPath, the instance properties are deallocated and appear as in the debugger.

The properties are being loaded from the database.

Foo.h

NSString *prop1;

@property(nonatomic, retain)NSString *prop1;
-(void)shouldLoadProperties;

Foo.m

@synthesize prop1;

-(void)shouldLoadProperties {
    <FMDatabase stuff here>

    FMResultSet *rs = [self executeQuery:sql];
    prop1 = [rs stringForColumn:@"col1"];  //loads db value "Test" into prop1
}

The tableview controller:

TestTableViewController.h

Foo *foo;

TestTableViewController.m

-(void)viewDidLoad {
   foo = [[[Foo alloc] init] retain];
   [foo shouldLoadProperties];

   //Breakpoint here shows that foo.prop1 is set to "Test"

}

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

   //foo is is still allocated, but foo.prop1 has been 
   //deallocated;  shows as <freed object>  

  NSLog(@"Prop 1 is %@", foo.prop1);  //throws exception


}

I’m not releasing foo, so why would the properties deallocate themselves? Am I missing something in Foo to hang onto the properties until the instance is released?

UPDATE

I found that by adding retain when populating the property from the database, that the data holds:

 prop1 = [[rs stringForColumn:@"col1"] retain];

Is this correct or am I missing something else?

  • 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-06-02T05:30:11+00:00Added an answer on June 2, 2026 at 5:30 am

    The problem here is that you’re not using prop1 as a property, but as a variable within your class. You can and should give these different names. It’s customary to put an underline at the start of the variable name:

    foo.h

    NSString *_prop1;
    
    @property(nonatomic, retain)NSString *prop1;
    -(void)shouldLoadProperties;
    

    foo.m

    @synthesize prop1 = _prop1;
    

    Now, to actually use your properties, use the getters and setters. This will retain your value and release it when appropriate.

    [self setProp1:[rs stringForColumn:@"col1"]];  //loads db value "Test" into prop1
    

    and

    self.prop1 = [rs stringForColumn:@"col1"];  //loads db value "Test" into prop1
    

    are both valid and equivalent to each other.

    _prop1 = [rs stringForColumn:@"col1"];  //loads db value "Test" into prop1
    

    Will lead to crashing and other bad behavior.

    Your update will prevent the crash, but will leak memory if you do it more than once.

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

Sidebar

Related Questions

I have been working on an object class for my iPhone app that lazy
I have put one global tabBarController in iphone app that I have been working
I'm working on a very simple iPhone app, that in the end will have
I have a medical app for the iPhone that I'm working on, where a
I'm working on an iPhone app that will have involve a lot of forms.
I am using in-app purchase for an iPhone app. I have a class that
I have a nice working iphone app that works with core data. I use
I am working on an iPhone app, in which I have to enlist all
I have a working table view on my iphone app, and am implementing a
I'm working on a simple iPhone app. I have 1 UINavigationController and 2 subclasses

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.