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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:26:40+00:00 2026-06-15T00:26:40+00:00

thanks for viewing this post, it’d be great if you guys can help me

  • 0

thanks for viewing this post, it’d be great if you guys can help me out. I’ve been doing some objective-c and learned about the objective-c way of memory management, like making sure to call release whenever I own the object, when to call autorelease, etc. I also do not want to use ARC or the newly introduced GC because I like to manage my own memory, I plan to advance later on into iOS development, and I know it’s a good practice to manage my own memory. But there’s still one small detail that I seem to have hit a brick wall in. It has to do with sending objects the -retain message. I learned that sending the -retain message increments the reference count by 1. But would this be an appropriate time to send -retain? :

      - (void) setName : (NSString* ) theName 
      {
          // name is an instance variable of type NSString
          [theName retain]; // Must release this
          name = [theName copy]; // Must release this in dealloc
          [theName release]; // decrement the reference count because of retain
      }

Should I call retain here so that I own the argument temporarily and ensure it doesnt’
get released somehow before I get to use it?

Any help would be appreciated! Thanks!

  • 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-15T00:26:41+00:00Added an answer on June 15, 2026 at 12:26 am

    No. You the object supplied as an argument to the method will generally be around until your method returns. You don’t need the retain messages there. You copy the string here to keep it around after the method returns.

    This is documented in Apple’s Documentation on this page in the “Avoid Causing Deallocation of Objects You’re Using” Section. Specifically:

    Cocoa’s ownership policy specifies that received objects should
    typically remain valid throughout the scope of the calling method. It
    should also be possible to return a received object from the current
    scope without fear of it being released. It should not matter to your
    application that the getter method of an object returns a cached
    instance variable or a computed value. What matters is that the object
    remains valid for the time you need it.

    As an aside you really should consider using ARC. Its not good practise to manage your own memory. No matter how good one can be at managing their own memory the LLVM compiler is still better. Managing your own memory will lead to hard to troubleshoot issues caused only by yourself. It is an extra level of cognitive load that you really don’t have to deal with and, when you finally let manual memory management go, you will breathe a sigh of relief at all the mental overhead you didn’t even know was there.

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

Sidebar

Related Questions

Thanks for viewing this. I need a little bit of help for this project
Thanks to some help I received yesterday I've got some dynamic summing working on
I have been scouring the internet trying to figure this one out. Any ideas
This is sort of a complex issue, hopefully you can help. I am using
I have been trying to figure this out all afternoon with no luck. On
Hello everyone and thanks for viewing this question :) I am an indie to-be-developer
I created a web page for viewing images. This page has some other code
Need help! I've been looking for a solution for this seemingly simple task but
Thanks for viewing my question. Let me describe the app first. I have a
Thanks for the help on here with my query on here the other day

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.