in Technology by

What happens if you add your just created object to a mutable array, and you release your object?

1 Answer

0 votes
by

It depends. If you owned the object before adding it to the array, you still must release your own ownership claim to avoid a leak — the array’s ownership claim on the object is separate, and does nothing to absolve you of your own responsibility with respect to the memory management rules.

Object *obj = [[Object alloc] init];

[anArray addObject:obj];

[obj release];

On the other hand, if you did not own the object, then you still don’t own it after you add it to the array, and still must not release it. The array does establish its own ownership claim, but just like your own code, it’s responsible for balancing its own claims.

Object *obj = [Object object];

[anArray addObject:obj];

// or, avoiding a temp variable

[anArray addObject:[Object object]];

Related questions

0 votes
    What happens with the objects if the array is released?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    I currently have 2 classes: workerListClass workerClass The workerListClass gets a list of work with ids from ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    So like when working with mysql_fetch_object(), how do you do things like this: $array = array(); ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Have you ever created dashboard using procedures with input parameter? If your answer is yes, definitely the next question will be how?...
asked Nov 21, 2020 in Technology by JackTerrance
0 votes
    State true or false. When you have finished your work in the IMG or ABAP Workbench, or have reached a certain stage, you can release the request. A. True B. False...
asked Feb 20, 2023 in Technology by JackTerrance
0 votes
    You add a data disk to an Azure virtual machine. What drive type is created? SCSI IDE PATA SATA...
asked Aug 28, 2021 in Technology by JackTerrance
0 votes
    What happens if we put a key object in a HashMap which exists? (a) The new object replaces the ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Using tJavaFlex how many parts of java-code you can add in your Job? One Two Three Four...
asked Mar 25, 2021 in Technology by JackTerrance
0 votes
    How can you add reference of Handlebars in your project? (1)All the options (2)Using npm package manager (3)Using CDN (4)Using local reference (5)Using Bower package manager...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    8. To add tables to your slides, which menu will you use? * (a) Insert O (b) Edit O (c) Tools O (d) Format Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
0 votes
    what is mutable and immutable data type give two example of each Select the correct answer from above options...
asked Dec 2, 2021 in Education by JackTerrance
0 votes
    All pandas data structures are ___ mutable but not always _______mutable. (a) size, value (b) semantic, ... and answers pdf, Data Science interview questions for beginners...
asked Oct 29, 2021 in Education by JackTerrance
0 votes
    What happens if you view a new HTML5 form input type in an older browser?...
asked Apr 10, 2021 in Education by JackTerrance
0 votes
    What happens if you fail to make required premium payments?...
asked Dec 31, 2020 in Health by Editorial Staff
...