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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:06:13+00:00 2026-05-11T15:06:13+00:00

I’m new to Objective-C, and I can’t figure out why the NSString objects in

  • 0

I’m new to Objective-C, and I can’t figure out why the NSString objects in my array of Car objects seem to have been released.

Here’s my Car.m class:

 #import 'Car.h' @implementation Car @synthesize categoryId;  - (id)initWithPrimaryKey:(NSInteger)pk categoryId:(NSNumber *)catId carName:(NSString *)n {     if (self = [super init]) {         primaryKey = pk;         categoryId = catId;         name = n;     }      return self; } - (void)dealloc {     [name release];     [categoryId release];      [super dealloc]; } - (NSInteger)primaryKey {     return primaryKey; } - (NSString *)name {     return name; } - (void)setName:(NSString *)aString {     if ((!name && !aString) || (name && aString && [name isEqualToString:aString])) return;     [name release];     name = [aString copy]; }  @end 

And here’s my Simple_TableViewController.m class. The listData instance variable is set correctly in viewDidLoad(). In the debugger, the NSString *name property of each array element is intact. Then, in every other method, listData is corrupt. It has all the Car elements with the correct primaryKey and categoryId values, but the NSString *name property is ‘Invalid.’

 #import 'Simple_TableViewController.h' @implementation Simple_TableViewController  - (void)viewDidLoad {            NSMutableArray *array = [[NSMutableArray alloc] init];     Database *database = [Database instance];      array = [database getAllCars];     [self setListData:array];     [array release]; } - (NSMutableArray *)listData {     return listData; } - (void)setListData:(NSMutableArray *)newListData {     if (listData != newListData) {         [listData release];         listData = [newListData mutableCopy];     } } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {     return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (void)didReceiveMemoryWarning {     [super didReceiveMemoryWarning]; } - (void)dealloc {     [listData release];     [super dealloc]; } - (NSInteger)tableView:(UITableView *)tableView  numberOfRowsInSection:(NSInteger)section {     return [listData count]; } - (UITableViewCell *)tableView:(UITableView *)tableView             cellForRowAtIndexPath:(NSIndexPath *)indexPath {     static NSString *SimpleTableIdentifier = @'SimpleTableIdentifier';      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];     if (cell == nil) {         cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero                                                  reuseIdentifier:SimpleTableIdentifier] autorelease];     }      NSUInteger row = [indexPath row];     Car *car = [listData objectAtIndex:row];      cell.text = car.name;     cell.font = [UIFont boldSystemFontOfSize:17];      return cell; } - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath {     return 0; } - (NSIndexPath *)tableView:(UITableView *)tableView   willSelectRowAtIndexPath:(NSIndexPath *)indexPath {     NSInteger row = [indexPath row];     if (row == 0) {         return nil;     }      return indexPath; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {     NSUInteger row = [indexPath row];      NSString *message = [[NSString alloc] initWithFormat:@'You selected %@', [[listData objectAtIndex:row] name]];     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@'Row Selected!'                                                                     message:message                                                                   delegate:nil                                                       cancelButtonTitle:@'Yes I Did'                                                       otherButtonTitles:nil];     [alert show];      [message release];     [alert release]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {     return 35; }  @end 

I’ve fiddled with Zombie this and retain that until my fingers fell off. I did away with the @property (nonatomic, retain) and @synthesize stuff for the listData variable, and I still have the same problem.

Thanks in advance for any advice you have to offer!

  • 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-11T15:06:14+00:00Added an answer on May 11, 2026 at 3:06 pm

    In your initWithPrimaryKey:etc: method, you need to retain those values, or use the dot notation to assign them (assuming they are properties declared with the retain keyword). Try this:

     - (id)initWithPrimaryKey:(NSInteger)pk categoryId:(NSNumber *)catId carName:(NSString *)n {     if (self = [super init]) {         primaryKey = pk;         categoryId =[catId retain];         name = [n retain];     }

    return self; 

    }

    Also, and this is just a style issue, you might consider slightly more verbose names than ‘n’ and ‘pk’. Your future-self will thank you.

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

Sidebar

Ask A Question

Stats

  • Questions 107k
  • Answers 107k
  • 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
  • Editorial Team
    Editorial Team added an answer Because try { File.Open("FileNotFound.txt", FileMode.Open); } catch { throw; }… May 11, 2026 at 9:03 pm
  • Editorial Team
    Editorial Team added an answer You have a few options depending on your needs. For… May 11, 2026 at 9:03 pm
  • Editorial Team
    Editorial Team added an answer You can do a transaction scope: using (var transaction =… May 11, 2026 at 9:03 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.