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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:01:20+00:00 2026-05-15T08:01:20+00:00

This is KILLING me! I have a view. in the .h file i do

  • 0

This is KILLING me!

I have a view. in the .h file i do this:

@interface SearchLogs : UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, UIActionSheetDelegate, UIPickerViewDelegate> {

NSString *startDate;
NSDateFormatter *thisFormatter;
}


@property (nonatomic, retain) NSString *startDate;
@property (nonatomic, retain) NSDateFormatter *thisFormatter;
@end

There are other things in the @interface and @properties …but that is where i do startDate.

in the .m file i do this:

@implementation SearchLogs

@synthesize startDate;
@synthesize thisFormatter;

 - (void)viewDidLoad {
  NSLog(@"viewDidLoad\n");
  [super viewDidLoad];

 thisFormatter = [[NSDateFormatter alloc] init];
[thisFormatter setDateFormat:@"yyyy-MM-dd"];

  NSDate *today = [[NSDate alloc] init];
  NSLog(@"startDate refcount: '%i'\n",[startDate retainCount]);
  startDate = [thisFormatter stringFromDate:today];
  NSLog(@"startDate refcount: '%i'\n",[startDate retainCount]);
  [today release];
 }


- (void)viewWillAppear:(BOOL)animated {
 NSLog(@"viewWillAppear\n");
 [super viewWillAppear:animated];
 NSLog(@"startDate refcount: '%i'\n",[startDate retainCount]);
}


- (void)viewDidAppear:(BOOL)animated {
 NSLog(@"viewDidAppear\n");
 [super viewDidAppear:animated];
 NSLog(@"startDate refcount: '%i'\n",[startDate retainCount]);

}

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
 NSLog(@"numberOfSectionsInTableView\n");
 // Return the number of sections.
 NSLog(@"startDate refcount: '%i'\n",[startDate retainCount]);   
 return 6;

}

- (void)dealloc {

[startDate release];
 [thisFormatter release];

}

Here is my problem: My app crashes at numberOfSectionsInTableView

Here is the log:

2010-06-20 17:35:22.363 cConnect[10529:207] viewDidLoad
2010-06-20 17:35:22.376 cConnect[10529:207] startDate refcount: '0'
2010-06-20 17:35:22.378 cConnect[10529:207] startDate refcount: '1'
2010-06-20 17:35:22.378 cConnect[10529:207] viewWillAppear
2010-06-20 17:35:22.379 cConnect[10529:207] startDate refcount: '1'
2010-06-20 17:35:22.379 cConnect[10529:207] viewDidAppear
2010-06-20 17:35:22.380 cConnect[10529:207] startDate refcount: '1'
2010-06-20 17:35:22.381 cConnect[10529:207] numberOfSectionsInTableView
2010-06-20 17:35:22.381 cConnect[10529:207] *** -[CFString retainCount]: message sent to deallocated instance 0x5da5730

My main question is WHY? startDate is never explicitly released in my code. Is there something I am doing to cause it to be released without knowing it?

TIA

SLIGHT EDIT:

I tried replacing:

startDate = [thisFormatter stringFromDate:today];

with:

startDate = [[thisFormatter stringFromDate:today] retain];

and it is no longer crashing! I thought NSDateFormatter stuck around until the variable no longer needed it… 🙁 Am I misunderstanding convenience methods?

  • 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-15T08:01:21+00:00Added an answer on May 15, 2026 at 8:01 am

    Your problem is

     startDate = [thisFormatter stringFromDate:today];
    

    This gives you an autoreleased string. You must retain it. Either use

    startDate = [thisFormatter stringFromDate:today];
    [startDate retain];
    

    Or use the property and invoke the setter:

    self.startDate = [thisFormatter stringFromDate:today];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been killing me - I have a massive file that I need
Im killing the process in the port 4444, but this can change, i have
This has been killing me for two days now. I have a main Activity
This has been killing me for two days now. I have a main Activity
this is killing me but is there any simple way to have objective-c code
This is killing me!!! I seem to have done all I need to do
SQL guru needed, this is killing my neurons. I have a db structure (simplified)
This is not about terminating a system-process but killing myself. I have several parallel
This should be a simple one: I have an observableArray object called To in
I have been stuck on this for a few days now and it is

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.