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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:53:12+00:00 2026-05-25T13:53:12+00:00

Here I got some ugly code: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@yyyy];

  • 0

Here I got some ugly code:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy"];
NSDate *date = [NSDate date];
NSString *textWithYear = [NSString stringWithFormat:@"text and year %@", [dateFormatter stringFromDate:date] ];
[dateFormatter release];
NSLog(@"%i", [dateFormatter retainCount]); // returns 1 !

As you see, retains counter returns 1, which I suppose means that the object is not released.
If I change that string to

[dateFormatter release], dateFromatter = nil;

retains counter returns 0, which is supposedly because it can’t count retains for nil 🙂

Is there something that I don’t understand about retains counter, or this object is really not released? When I send release to it for the second time (striving to get zero retains count) it crushes expectedly 🙂

And one more question: if the dateFormatter was really released, why doesn’t it crash when i call [dateFormatter retainCount] ?

  • 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-25T13:53:13+00:00Added an answer on May 25, 2026 at 1:53 pm

    You are correctly releasing your object; don’t worry about the retain count. And don’t use -retainCount. See When to use -retainCount? or Calling -retainCount Considered Harmful for more details about why.

    Do note that your code here will crash if the object does get destroyed (because the call to -retainCount comes after you’ve released it and may be to a dangling pointer); setting your variables to nil after you are done with them is a good habit to protect against this. But it has nothing to do with whether your code is leaking.

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

Sidebar

Related Questions

I got some sample code from the net here: http://www.javadb.com/sending-a-post-request-with-parameters-from-a-java-class That works fine. It
I've got some code here that works great on IPv4 machines, but on our
I've got a quite strange problem here. I'm calling some simple code via Ajax.Updater:
I've got some code that's basically identical to the jQuery UI Sortable example here:
Got some code here that isn't working: $(#sidebar ul li:last).each(function(){ $(this).addClass(last); }); Basically I
I've got some legacy code in C++ here that does some things I don't
I've got some code here that will create a basic table in a Word
Here's the situation: I've got some lengthy non-UI code that needs to be run
Here i've got some code to transfer an inner core model to an output
Hey everyone, great community you got here. I'm an Electrical Engineer doing some programming

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.