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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:10:45+00:00 2026-05-25T23:10:45+00:00

Assuming, the following declaration for class A @property(nonatomic, assign) DoublyLinkedList *doublyLinkedList; , that as

  • 0

Assuming, the following declaration for class A

@property(nonatomic, assign) DoublyLinkedList *doublyLinkedList;

, that as part of init, initialized the object

- (id)init {
    self = [super init];
    if (self) {
        doublyLinkedList = [[DoublyLinkedList alloc] init];
    }

    return self;
}

and that a method

- (DoublyLinkedList*) doSomethingAndReturn {

that ultimately

return doublyLinkedList;

Does class A owns the doublyLinkedList after the return?

  • 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-25T23:10:46+00:00Added an answer on May 25, 2026 at 11:10 pm

    EDIT: init added with alloc

    You are not calling retain on it, but in init you are calling alloc on it, so it does have a retain count of 1 — you own it and you should release it in dealloc.

    You could simply alloc it and release it in dealloc. The caller of the property can choose whether to retain. Another option would be to create the object in init, autorelease it and then assign it to the property with (retain) instead of (assign). That way, if other places in the code alloc and assign to that property, the object you alloc‘d will get released. Then in dealloc, what it’s currently assigned to will get released.

    Yet another option if you don’t want others to set it would be to have a (readonly) property and a _doubleLinkedList iVar and then @synthesize doublyLinkedList = _doubleLinkedList. Then you can allocate it once in init and know that no one else will assign it, and then release it in dealloc.

    A good analogy is that when you retain, you’re putting a leash on it. Multiple items can put a leash on that object. It is freed only when everyone has taken the leash off.

    A good guide to read:

    Apple’s Memory Management Programming Guide

    Specifically from that doc, these rules help:

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

    You can take ownership of an object using retain A received object
    is normally guaranteed to remain valid within the method it was
    received in, and that method may also safely return the object to its
    invoker. You use retain in two situations: (1) In the implementation
    of an accessor method or an init method, to take ownership of an
    object you want to store as a property value; and (2) To prevent an
    object from being invalidated as a side-effect of some other operation
    (as explained in “Avoid Causing Deallocation of Objects You’re
    Using”).

    When you no longer need it, you must relinquish ownership of an
    object you own
    You relinquish ownership of an object by sending it a
    release message or an autorelease message. In Cocoa terminology,
    relinquishing ownership of an object is therefore typically referred
    to as “releasing” an object.

    You must not relinquish ownership of an object you do not own This
    is just corollary of the previous policy rules, stated explicitly.

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

Sidebar

Related Questions

Assuming the following Model: class Model < ActiveRecord::Base def initialize(*args) super self.du = 1000
Assuming the following model: class Category(models.Model): related = models.ManyToManyField('self', symmetrical = False, through =
assuming the following html (minus the comments and nbsp; etc that xQuery wont process
Assuming a method with the following signature bool TryXxxx(object something, out int toReturn) What
Though i am using Objective-C syntax, the question language agnostic. Assuming the following declaration
Assuming following code. There is class MyStream witch has template overloaded operator <<. There
i have populated gridview from SaleDAL class, assuming following is the code, Please ignore
Assuming the following: def create_new_salt self.salt = self.object_id.to_s + rand.to_s end Why is it
Assuming the following view model definition: public class MyObject { public string Name {
In my class, I want to use a dictionary with the following declaration: Dictionary<string,

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.