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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:13:30+00:00 2026-06-03T09:13:30+00:00

This is a question related to Objective-C memory management. On the About Memory Management

  • 0

This is a question related to Objective-C memory management.

On the About Memory Management page there are some examples

- (NSString *)fullName {
   NSString *string = [[[NSString alloc] initWithFormat:@"%@ %@",
                                  self.firstName, self.lastName] autorelease];
   return string;
}

and the second one

- (NSString *)fullName {
   NSString *string = [NSString stringWithFormat:@"%@ %@", 
                                  self.firstName, self.lastName];
   return string;
}

The only difference is that in the first example an initializer is called, and in the second a class factory method.

Basic memory management rules section is said that after an alloc call I will own the object I allocated. So in the first example I allocate an object and at the same time initialize it. In this I own the object and have to release it. In the second example I don’t. But doesn’t the factory method stringWithFormat: do the same thing in one call, I mean allocating the object and initializing it?

So the main question is, why don’t I have to release the object in the second example?
are there any special memory management rules when implementing a class factory method?

  • 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-06-03T09:13:31+00:00Added an answer on June 3, 2026 at 9:13 am

    By convention, a class factory method will return an object that is in the autorelease pool. It has done the alloc, init, autorelease for you, just like in the first example. Unless you retain it, when the pool is drained, it will be released.

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

Sidebar

Related Questions

This question is related with one of my earlier questions.. Previous Post In there
This question is related to my other question How to redirect to Login page
This question is related to one of my others about C: What can you
Note: This is not an Objective-C question and is not related to objective-c. Re:
OK, this is related to question Constants in Objective C . I created Constants.h
This is related to question Java Appengine APPSTATS causing java out of memory error
Please note this question related to performance only. Lets skip design guidelines, philosophy, compatibility,
This question is related to my problem in understanding rebase, branch and merge ,
This question is related to a previous question of mine That's my current code
This question is related to Java Refuses To Start - Could Not Resrve Enough

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.