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

The Archive Base Latest Questions

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

I have Util class as follows. @implementation Util – (NSString*) getTodayString { NSDate *today

  • 0

I have Util class as follows.

@implementation Util

- (NSString*) getTodayString
{

    NSDate *today = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        // display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings
    [dateFormatter setDateFormat:@"YYYY/MM/dd"];
    NSString *now = [dateFormatter stringFromDate:today];

    [dateFormatter release]; ///???
    [today release]; //???
    return now;
}

@end

And I use the class

- (void)awakeFromNib
{
    Util *ut = [[Util alloc] init];
    NSString* now = [ut getTodayString];
    NSLog(@"User's current time in their preference format:%@",now);

    [currentTime setObjectValue:now];
    [now release]; ///???
    [ut release];
}

I’m confused when releasing objects.

In getTodayString ::

Q1. [dataFormatter release] is necessary?
Q2. [today release] is necessary?

I guess I don’t need to release them as I didn’t alloc myself. If that’s true, when those objects are released?

In awakeFromNib ::

Q3. [ut release] is necessary?
Q4. [now release] is necessary?

I guess I have to release ut as I create the object explicitly, but not suer about now object.

  • How one can determine when is the object is released?
  • With python/C#/Java one doesn’t care about this kind of deallocation of memory anymore. Is it also OK with Objective-C if I don’t care about them?
  • 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-20T08:43:16+00:00Added an answer on May 20, 2026 at 8:43 am

    Q1. [dataFormatter release] is
    necessary? Q2. [today release] is
    necessary?

    dataFormatter: yes, you alloc/init’d it.
    today: no, it was returned autoreleased from a factory method.

    Q3. [ut release] is necessary? Q4.
    [now release] is necessary?

    The same,

    ut: yes, you alloc/init’d it.
    now: no, it was returned autoreleased from a factory method.

    How one can determine when is the
    object is released?

    it’s released when release is called on it, if autorelease is called, release will be called during the next run of the Autorelease Pool.

    Is it also OK with Objective-C if I
    don’t care about them?

    No, it’s not ok. If you do not clean up after yourself you will have substantial memory leaks, in the iOS environment that means a quite shutdown of your app. In a Mac app that can lead to eating up a ton of memory and not being a good citizen. This is assuming a non garbage collection environment. Ie most.

    I’m guessing the heart of your question is you aren’t sure when you are responsible for calling release and when you get an autoreleased object (or rather, when you are responsible for calling release on the object). It’s by convention. If you call any method that returns an object that does not contain the words: init/copy then it is not your responsibility to call release. If you retain, you release (There may be some more rules to follow, but that’s the first one to really start understanding this, in my opinion). If you ever call alloc/init/copy, then you must call release at some point.

    A GREAT teacher is Build & Analyze in Xcode. This will quickly point out where you screwed up and really help to understand what is going on.

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

Sidebar

Related Questions

I have developed a composite component as follows... <composite:implementation> <div class=numericBox> <h:inputText id=txtInput size=#{cc.attrs.maxLength}
I have a static util class that does some string manipulation on a bit
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
please have a look at the following code import java.util.ArrayList; import java.util.List; public class
I have the following simple Java code: package testj; import java.util.*; public class Query<T>
I have a problem with portlet. When i write in portlet.xml standart line <portlet-class>com.liferay.util.bridges.mvc.MVCPortlet</portlet-class>
I have two Java instances of java.util.Date and I have to find out if
I have an Address object defined simply as follows: public class Address { public
I have a hibernate mapping as follows: <hibernate-mapping> <class name=kochman.elie.data.types.InvoiceTVO table=INVOICE> <id name=id column=ID>
I have a Candidades class that holds Candidate objects, as follow: import java.util.*; public

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.