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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:43:03+00:00 2026-05-21T19:43:03+00:00

I am a new Objective-C programmer and sometimes confused with those ownership concepts of

  • 0

I am a new Objective-C programmer and sometimes confused with those ownership concepts of this language….currently i am learning the iPhone programming….

Here are case those confused me always..

i use normally these (sometimes first and sometimes other)

 NSMutableArray *array;     //Declared in header

case 1

array1= [databaseClass getData];

Case 2

array1 = [NSMutableArray arrayWithArray:[databaseClass getData]]; 

Here [databaseClass getData] returns a nonAutoreleased array of objects..
I just want to conforms that is anyone of them is correct ?

and if not then please suggest the correct one….

EDIT

I mean to say that [databaseClass getData] already returning me an allocated array (i means a non-autoreleased array) now i think i do not need to allocate my array if i want to use it in my class (i have tested this and it works) , here my only question is about that array1 initialization….Does anyone of those above statements make any sense……if no then i request that please provide a block of code so that it becomes more clear to me…..
Thank You

  • 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-21T19:43:04+00:00Added an answer on May 21, 2026 at 7:43 pm

    Both cases should give you an autoreleased object. You’re the owner if:

    • You allocated the object via alloc.
    • You created a copy of an object via a method that contains the word copy, as in mutableCopy (the returned copy belongs to you, not the object on which you called the copy method).
    • You retained it.

    In all other cases you can assume that you are not the owner and that you do not need to release the object.

    So if your getData method does not return an autoreleased object you should modify it so it does. Otherwise other people using this code will create memory leaks (and you’re likely to confuse yourself this way).

    Edit after question got edited:

    According to the naming convention in Objective-C, the getData method should return an autoreleased object. So it should be edited to return an autoreleased object if it doesn’t already.

    If you want to edit the array you do need to make a mutable copy from it. You can either call [NSMutableArray arrayWithArray:[databaseClass getData]]; or [[databaseClass getData] mutableCopy]. In the first case, the array is autoreleased, you are not the owner and you do not need to call release on it. In the second case, you are the owner (as per the copy rule) and need to release it later on.

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

Sidebar

Related Questions

I am new to Objective C and iPhone development. I am using CoreData on
I am new to Objective-C and I have no clue why this code is
I am a new objective-c/iPhone developer and am wondering if there is any way
I am a new objective-c/iPhone developer and am wondering if there is any way
New to objective-c and I just can't find the answer to this question anywhere.
New to Objective-C iPhone/iPod touch/iPad development, but I'm starting to discover lots of power
I am still new to objective-c and am trying to figure out what this
I'm fairly new to Objective-C, and am currently reading up on memory management. I'd
I'm new with Objective C and am not an uber programmer anyway but one
I am a new Objective-C programmer coming from a C#, VB.NET, Etc. These are

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.