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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:29:34+00:00 2026-05-27T06:29:34+00:00

As part of the Mac OS X developer library, there is a very good

  • 0

As part of the Mac OS X developer library, there is a very good memory management guide for objective c. It not only describes what the various memory management functions (such as retain, autorelease and dealloc) do, but when to use each method.

For example, it has the following guidelines for releasing memory:

  • You must not relinquish ownership of an object you do not own
  • When you no longer need it, you must relinquish ownership of an object you own
  • You can take ownership of an object using retain
  • You own any object you create

It then gives detailed information about these rules, eg

You create an object using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, alloc, newObject, or mutableCopy).

By following these guidelines, it makes it easy for people using your code to know when they are expected to retain or release objects returned from methods and when it isn’t necessary.

Also, the guide is obviously written by people with years of experience working with objective c. So in the vast majority of cases, following the memory management guidelines would produce better code than coming up memory management guidelines yourself.


Due to these advantages, I was wondering if there was a similar guide somewhere for c++. There are many ways you can pass or return an object to a method in c++:

  • by reference
  • by value
  • by pointer
  • by boost::shared_ptr (or other smart pointers)
  • const variants of the above methods

I understand how they work, but I am constantly unsure of what method I should use. There are so many different pros and cons to each method that I find I am wasting too much time deciding what method to use, only to change it later on when I find I made the wrong choice.

If I had a memory management guide for c++ like the objective c guide, it would be a much simpler job. So is there one around, either on a website or published in a book? Also, is there a set of guidelines that most c++ developers follow?

  • 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-27T06:29:34+00:00Added an answer on May 27, 2026 at 6:29 am

    The difference is that for Objective C you are presented with a convention that is used in the standard library and that is also used practically in every program for that platform.

    C++ instead is agnostic in respect to which policy you may want to use for your application and therefore there are no general rules you can follow. If you use smart pointers there are certain rules, if you use hierarchical ownership (like in Qt) there are other rules, if you use a garbage collected approach rules change again.

    More or less like for hardware, problems are simpler in Apple approach because there is no variety. It’s debatable if that variety is an important resource worth fighting the included complexity or just a pointless complication.

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

Sidebar

Related Questions

Now that Xcode is part of the App Store (I'm not a paid developer
i'm porting an iphone app to Mac app,there i have to change all the
Two part question: Does the iPhone have a unique ID other than it's MAC
I want to put an icon in Mac OS status bar as part of
Exposition: I am on Linux / Mac. Part of my code is in Java,
I am developing a Mac OS X application which, as part of it's UI,
As part of a Mac application I am working on, the user fills out
I trying to make minimal part of Python to work as part (static library)
I'm part of a team developing a fairly large iPad app and there are
Part of my code relies on a comparison between two items, and it may

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.