in Education by
I'm still trying to understand this piece of code that I found in a project I'm working on where the guy that created it left the company before I could ask. This is the code: -(void)releaseMySelf{ for (int i=myRetainCount; i>1; i--) { [self release]; } [self autorelease]; } As far as I know, in Objective-C memory management model, the first rule is that the object that allocates another object, is also responsible to release it in the future. That's the reason I don't understand the meaning of this code. Is there is any meaning? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The author is trying to work around not understand memory management. He assumes that an object has a retain count that is increased by each retain and so tries to decrease it by calling that number of releases. Probably he has not implemented the "is also responsible to release it in the future." part of your understanding. However see many answers here e.g. here and here and here. Read Apple's memory management concepts. The first link includes a quote from Apple The retainCount method does not account for any pending autorelease messages sent to the receiver. Important: This method is typically of no value in debugging memory management issues. Because any number of framework objects may have retained an object in order to hold references to it, while at the same time autorelease pools may be holding any number of deferred releases on an object, it is very unlikely that you can get useful information from this method. To understand the fundamental rules of memory management that you must abide by, read “Memory Management Rules”. To diagnose memory management problems, use a suitable tool: The LLVM/Clang Static analyzer can typically find memory management problems even before you run your program. The Object Alloc instrument in the Instruments application (see Instruments User Guide) can track object allocation and destruction. Shark (see Shark User Guide) also profiles memory allocations (amongst numerous other aspects of your program).

Related questions

0 votes
    I'm still trying to understand this piece of code that I found in a project I'm working on where ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    How do I call Objective-C code from Swift?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    A number of cats got together and decided to kill between them 999919 rats. Every cat killed an equal number of rats. Each cat ... cat killed ? A) 1009 B) 991 C) 2000 D) 1000...
asked Feb 12, 2021 in Education by JackTerrance
0 votes
    ______________ are JS functions that you can call from your templates, and encourage you to reuse code and build complex templates a)Expressions b)Helpers c)Template d)Context...
asked Apr 29, 2021 in Technology by JackTerrance
0 votes
    The main objective of the political party is to capture ………………………. and retain it. (a) publicity (b) victory (c) power (d) information Please answer the above question....
asked Aug 14, 2022 in Education by JackTerrance
0 votes
    Suman asked her friend Niharika her English Copy. However she didn't gave suman. What do you think might ... behind this communication. Select the correct answer from above options...
asked Dec 10, 2021 in Education by JackTerrance
0 votes
    Suman asked her friend Niharika her English Copy. However she didn't gave Suman. What do you think might ... behind this communication. Select the correct answer from above options...
asked Dec 10, 2021 in Education by JackTerrance
0 votes
    How do you think this has benefitted them?...
asked Feb 22, 2021 in Technology by JackTerrance
0 votes
    Explain how to call function in Objective-C....
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    What do you think about BPEL and BPM? How do they compare?...
asked Jun 6, 2021 in Technology by JackTerrance
0 votes
    What do you think about the future of blockchain?...
asked Dec 26, 2020 in Technology by JackTerrance
0 votes
    60. “What do you think”?Recognise the type of sentence. (A) optative (B) negative (C) positive (D) interrogative Select the correct answer from above options...
asked Dec 5, 2021 in Education by JackTerrance
0 votes
    60. “What do you think”?Recognise the type of sentence. (A) optative (B) negative (C) positive (D) interrogative Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    60. “What do you think”?Recognise the type of sentence. (A) optative (B) negative (C) positive (D) interrogative Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    You are working with this XML code snippet from the XML document cars.xml. You need to return the information about the cars ... D.doc("cars.xml")/cars/car[integer(year) > 2000]...
asked Mar 10, 2023 in Technology by JackTerrance
...