Does it matter if main () creates an NSAutoreleasePool and drains it before exiting?

Because if it main()creates NSAutoreleasePooland depletes it before the program is released, then even though it can prevent a memory leak, all the space for the entire system will be freed up in any case - it matters if we free small pieces, if the whole part is freed further ? In fact, if he continues to work on small pieces, won't the program make it slower?

( draincan cause releasewhich, in turn, cause dealloc, but if dealloc- it’s only freeing up memory, but nothing else (for example, closing a file), then wo drainn’t help free up memory)

+3
source share
2 answers

It was believed that it was good practice to cleanse after yourself where possible, rather than relying on the environment to do it for you. If all that bothers you is memory usage, then no, the topmost pool is not strictly needed, but this is not the only thing you need to consider. Objects can do something other than free memory in their methods -dealloc(for example, delete files to disk, free rare OS resources, or free resources that otherwise would not be returned to the system when the process exits.)

Not to mention console spam, when objects receive auto-implementation without the presence of a pool.

+5
source

GUI dealloc . , . , dealloc, , , .

, , ( ). GUI. , , , , . , exit() .

+4

All Articles