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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:12:46+00:00 2026-05-16T06:12:46+00:00

Is it best to have static constructors where you alloc the instance in the

  • 0

Is it best to have static constructors where you alloc the instance in the constructor and you return the instance as auto release, e.g. [String stringWithFormat...] or is it best to have dynamic constructors where you ask the user to alloc first so that he is in charge of releasing? When should you use each?

Cheers

  • 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-16T06:12:46+00:00Added an answer on May 16, 2026 at 6:12 am

    I’m not sure whether “static” and “dynamic” are the appropriate terms.

    [NSString stringWithFormat:...] is a convenience method. If you want a formatted string that you aren’t going to keep for very long, you can use this convenience method to avoid the clutter that alloc+initWithFormat:+release may introduce into your [otherwise simple] code.

    [[NSString alloc] initWithFormat:...] is sometimes clearer to the reader that the lifetime of this object will be handled explicitly (i.e. with a release later), although, I have found it is not uncommon to encounter a [[[NSString alloc] initWithFormat:...] autorelease] in places.

    When you are designing a class, you should determine whether instances of your class are intended to be used frequently/quickly rather than long-term (or both). If you consider that your classes can be used frequently or quickly, then providing the convenience method will help reduce clutter and simplify the code that utilises the class.

    For example, NSWindow is not an class that you create and delete instances of frequently, so there are no convenience methods for creating NSWindow instances, you have to go through the alloc+init route (in fact, NSWindow is not normally an class that you have to create instances of manually anyway). On the other hand, strings, arrays, dictionaries, sets, and so on, these are all things that are often created and discarded frequently, so they all have convenient methods that make creating them and managing them easier.

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

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer TimeSpan has no formatting options at all before .NET 4.0,… May 16, 2026 at 9:52 am
  • Editorial Team
    Editorial Team added an answer Hi we had exactly the same issue, we solved it… May 16, 2026 at 9:52 am
  • Editorial Team
    Editorial Team added an answer You should at least properly quote your data to avoid… May 16, 2026 at 9:52 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a list of US regions set up as checkboxes. When a user
Anyone have any best practices tips for Rails and sessions? The default session type
I have a client/server question that i am trying to figure out the best
Since AS3 does not allow private constructors, it seems the only way to construct
Let's say I have a class which, internally, stores a List of data: import
I have many entry points in my assembly and I want some initialization code
Ok. So I have a list of values, and I'd like to do something
My generic question is as the title states, is it best to load data
I have an UITableView showing custom view cells that I've designed in interface builder.
I have some class it is a singleton we have this class in already

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.