[ACCEPTED]-Objective-C autorelease memory management-cocoa-touch

Accepted answer
Score: 15

An autoreleased object is added to an autorelease 12 pool.

Objects in the autorelease pool are 11 released at the end of an iteration of the 10 main runloop (or sooner if you are managing 9 your own autorelease pool and/or if you 8 call drain).

When you call a method that 7 returns an autoreleased object, it is pretty 6 much guaranteed to stay valid until at least 5 the end of the scope that it was called 4 in.

If you want to ensure that it stays alive 3 longer then you should retain it, remembering 2 to release it again when you're finished 1 with it.

Score: 0

How can i safely use the returned autoreleased 7 object inside my runIt method if i dont 6 know when the autorelease trigger?

Autorelease 5 will trigger after the current run loop 4 ends.

Should i retain the object returned 3 by the createNewTest ? or can i safely use 2 it within the runIt scope?

You can safely 1 use it inside the runIt scope.

More Related questions