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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:23:52+00:00 2026-05-15T05:23:52+00:00

Please see my comments in code: -(id)initWithCoordinate:(CLLocationCoordinate2D)c title:(NSString *)t { [super init]; coordinate =

  • 0

Please see my comments in code:

-(id)initWithCoordinate:(CLLocationCoordinate2D)c title:(NSString *)t
{        
    [super init];
    coordinate = c;
    NSDate *today = [NSDate date];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterLongStyle];

    NSString* formattedDate = [NSString stringWithFormat:@"%@ %@",
                           [dateFormatter stringFromDate:today], t];


    [self setTitle:formattedDate]; //Why does the app crash when I try and release formattedDate?  I have after all passed its reference to the title property?


    [dateFormatter release]; //I need to release the dateformatter because I have finished using it and I have not passed on a reference to it

    return self;
}
  • 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-15T05:23:53+00:00Added an answer on May 15, 2026 at 5:23 am

    Nope, looks fine. stringWithFormat returns an autoreleased object – you don’t own it unless you retain it, which you haven’t, so you mustn’t release it. You allocated dateFormatter yourself, so you do own it and must release.

    (See the object ownership documentation and 8 squillion very similar SO questions. This must be the number one objective-c problem that crops up here by a significant margin.)

    Edit: Actually, looking at your comment, there is a very slightly subtler issue here, though the upshot is the same (and actually underlines the point about ownership).

    When you pass the string to setTitle, it could retain the string itself, in which case a call to release here might not cause a crash immediately. You would still be over-releasing, however, and it would bite you in the end. It just would be more difficult to locate the cause of the problem further down the line.

    As it happens, setTitle makes a copy rather than retaining yours. This is pretty common with NSString properties. One reason is that you might pass an NSMutableString instead, and then randomly change it at some later point that might screw up the receiver. Taking a private copy is safer. As a bonus it exposes your over-releasing right away and allows you to fix it easily.

    In any case, the point stands: only ever release something you know you own. If you’ve just passed it to some other object, it’s that object’s responsibility to handle whether it owns it or not, not yours.

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

Sidebar

Related Questions

Please see my pseudo-code below. The code comments should explain my problem. I'm new
Summarization: Please see Andreas' knowledgeable comments! ========================================== As shown in the following code, TForm7
I'm writing a simple program - please see below for my code with comments.
Please see below code: thrust::device_vector<int>::iterator whereToBegin = copyListOfNgramCounteachdoc.begin(); end = thrust::unique_by_key(end.first, end.first + numUniqueNgrams,end.second);
Please see the code snippet below : #include <iostream> using namespace std; int main()
How to take integer in hashlib.sha1(int). Please see the code in which i am
I have a textarea in C#, please see below code: <asp:Label ID=lblQuestions runat=server CssClass=addinfo>
Please see demo here: http://jsfiddle.net/mA6qm/1/ (expand console) Why aren't events being sent or received
Please see here , at the end of the post, the 70px author image
Please see this example: if (strlen($_SESSION['userDetails']['THISNAME']) == 0) { $_SESSION['userDetails'][''.$THISNAME.'Error'] = autofocus; include $docRoot/html/forms/reg/user_info.html.php;

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.