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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:24:34+00:00 2026-05-23T23:24:34+00:00

In my User singleton, I have the following method: – (void)updateUser:(NSDictionary*)userInfo { //uid, fullname,

  • 0

In my “User” singleton, I have the following method:

- (void)updateUser:(NSDictionary*)userInfo
{
    //uid, fullname, email are ivars
    [uid release];
    uid = [[NSString alloc] initWithString:[userInfo objectForKey:@"id"]];
    [fullName release];
    fullName = [[NSString alloc] initWithFormat:@"%@ %@", [userInfo objectForKey:@"fname"], [userInfo objectForKey:@"lname"]];
    [email release];
    email = [[NSString alloc] initWithString:[userInfo objectForKey:@"email"]];
}

Is this the proper way to set NSStrings? I tried using autorelease objects but they seem to be releasing too early.

Edit:
Nevermind I’m dumb. Completely forgot about NSMutableStrings

  • 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-23T23:24:35+00:00Added an answer on May 23, 2026 at 11:24 pm

    You haven’t given much information but that’s essentially how you create NSString objects and assign them to what is possibly instance variables in your singleton. The thing that you may want to watch out for is that you’re releasing the old objects before assigning a new one to the variable. Something could potentially go very bad if something accessed that variable between the release and the assignment. Unless you have to support Objective-C before 2.0 I would suggest using synthesized properties since they handle such memory issues securely for you.

    Autoreleasing an object basically means that the object is released automatically at a later point. You would use autorelease in situations where you allocate an object but have no ability to release it yourself, such as in a convenience allocation method like this:

    + (id)newObject
    {
        return [[[MyClass alloc] init] autorelease];
    }
    

    The memory management guidelines says that whoever allocates (or retains) an object should also release it once it no longer needs access to that object. Therefore, autorelease allows a method to return a newly created object and say that it no longer needs it. The caller would have to retain it if it needs it to stay around. If it don’t it will just release automatically after the caller goes out of scope.

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

Sidebar

Related Questions

I have an object, based on the Singleton design, that I use for user
I have some class CurrentUser class CurrentUser < User include Singleton end User is
I have this singleton: UserData.h @interface UserData : NSObject { User *user; } +
I have a singleton which once hit will load user profile information, I want
I have a singleton which stores some prudent information about the user of my
User is a model. I have 100 users. I need to present the list
We have a singleton template class as defines below template<class T> class Singleton{ T&
I have a singleton in my FTP app designed to store all of the
Can we have a model class which is singleton in Doctrine? For Singleton classes
I have a web application where I would like to pull user settings from

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.