in Education by
As I understand it, anything created with an alloc, new, or copy needs to be manually released. For example: int main(void) { NSString *string; string = [[NSString alloc] init]; /* use the string */ [string release]; } My question, though, is wouldn't this be just as valid?: int main(void) { NSAutoreleasePool *pool; pool = [[NSAutoreleasePool alloc] init]; NSString *string; string = [[[NSString alloc] init] autorelease]; /* use the string */ [pool drain]; } 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
Yes, your second code snippit is perfectly valid. Every time -autorelease is sent to an object, it is added to the inner-most autorelease pool. When the pool is drained, it simply sends -release to all the objects in the pool. Autorelease pools are simply a convenience that allows you to defer sending -release until "later". That "later" can happen in several places, but the most common in Cocoa GUI apps is at the end of the current run loop cycle.

Related questions

0 votes
    Does a thread created using performSelectorInBackground:withObject: creates its own autorelease pool?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    Which feature of java 8 enables us to create a work stealing thread pool using all available processors at ... Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    What are NSAutoreleasePool? When to use them?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    i am working on a MVC project in java. For my operation I use database many times. many times my ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    We have a few databases in Pricing Tier: Basic, S0... like below picture: These databases were created before a ... the Azure portal. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    How many memory layers are in the Oracle shared pool?...
asked Dec 18, 2020 in Technology by JackTerrance
0 votes
    Which of the following is advantage of using JDBC connection pool? (a) Slow performance (b) Using more memory (c) ... & JDBC of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    Short version: How would i go about creating an object pool that can store classes of different types all ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I have not seen clear examples with use-cases for Pool.apply, Pool.apply_async and Pool.map. I am ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    Where is String Pool stored? (a) Java Stack (b) Java Heap (c) Permanent Generation (d) Metaspace ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Which of the following is advantage of using JDBC connection pool? (a) Slow performance (b) Using more ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    What is object pool in .Net?...
asked Jul 27, 2021 in Technology by JackTerrance
0 votes
    What is used for converting a pool of Docker hosts into a single, virtual Docker host? 1. Docker Images 2. Docker Compose 3. Docker Hub 4. Docker Swarm...
asked Jun 21, 2021 in Technology by JackTerrance
0 votes
    How does ChatGPT work?...
asked Jan 30, 2023 in Technology by JackTerrance
...