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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:22:43+00:00 2026-05-16T16:22:43+00:00

I have an NSDate object which I use in the main thread of my

  • 0

I have an NSDate object which I use in the main thread of my iPhone app and I also reference it from a background thread, its defined like this:

//header
NSDate *currentDate;
@property (nonatomic, retain) NSDate *currentDate;

//implementation file
@synthesize currentDate;

Then in my app, I call a refreshData method which passes that object to another helper class to get some data from a remote service:

- (void) reloadData: (NSInvocationOperation*)operation  
{
    //...
    NSMutableArray *results = [managerHelper refreshForAddress: address 
                                                      timeFrom: fromDate
                                                        timeTo: self.currentDate];
    //...
}

(note the above call is on the background thread)

now, in side that helper class, I have added these lines

- (NSMutableArray*) refreshForAddress:(NSString *)address 
                            timeFrom:(NSDate*) fromDate 
                              timeTo:(NSDate*) toDate
{
    debugLog(@"retain count: %i", [toDate retainCount]);
    NSNumber *toTimeNumber = [[NSNumber alloc] initWithDouble: [toDate timeIntervalSince1970]*1000];
    debugLog(@"after retain count log");
}

But I get the classic error: “*** -[__NSDate timeIntervalSince1970]: message sent to deallocated instance 0x71beea0”

And the logging says:

MyApp[5487:7903] retain count: 2
MyApp[5487:7903] *** -[__NSDate timeIntervalSince1970]: message sent to deallocated instance 0x71beea0

So, as you can see the last log statement doesnt get called, but the retainCount is 2, how can this be when I get that error the line after the log call???

  • 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-16T16:22:43+00:00Added an answer on May 16, 2026 at 4:22 pm

    You said you use two or more threads.
    So, you should define property as following way,

    @property (retain) NSDate *currentDate;  ///< atomic default
    

    This way will guarantee thread-safe for this property.

    Edit:

    Remove the “nonatomic” from @property, and it will behave as an atomic operation by default. The atomic operation will guarantee thread-safe behavior.

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

Sidebar

Related Questions

i have an NSDate object from an old date which i am getting from
I have a data structure object which is loaded from an XML file inside
I have an events app which gets events data from sqlite database and displays
I have an iOS app which gets some JSON from a server (in the
I have an NSDate object called 'dueDate'. I'm trying to work out how to
I have a Core Data Object Which is Composed of Different Types NSString, Float,NSDATA,....
I have a class called XYZ inheriting from NSObject and an array which contains
I have a Download object which handles NSURLConnection . Then I have NSOperation object
In the iPhone Push Notification documentation, they have a code snippet in which they
Writing an iPhone app in Objective-C, I have a date in string form (in

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.