Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>how are you creating this thread? NSThread? NSOperation and NSOperationQueue? GCD?</p> <p>For NSThread and NSOperation, you're supposed to create your own autorelease pool as part of setting up the thread. That way temporary objects get managed correctly within that thread.</p> <p>I believe GCD takes care of this detail for you.</p> <p>In newer versions of Objective C (Objective C 2.0, I believe) you should use the new syntax </p> <pre><code>@autoreleasepool { //Code to use a local autorelease pool } </code></pre> <p>For loops that generate a ton of temporary objects, you can create a local autorelease pool for any block of code. You could refactor your code like this:</p> <pre><code>while(1) { @autoreleasepool { NSArray *files = [nfm contentsOfDirectoryAtPath:dataDir error:nil]; /* if(files == nil) break; if([files count] &lt;= 0) { files = nil; [NSThread sleepForTimeInterval: 5.0f]; continue; } if(![ViewController obtainLock]) { files = nil; continue; } */ //[ViewController releaseLock]; files = nil; } } </code></pre> <p>That would cause it to create a new autorelease pool for each iteration of the loop, and drain it at the end (thus releasing all temporary objects created in that iteration.)</p> <p>By the way, if you're using NSThread, don't. Learn how to use GCD instead. GCD (Grand Central Dispatch) makes MUCH more efficient use of system resources than NSThread. NSThread is based on POSIX threads, which are very expensive to create, and tie up physical memory on the device for the life of your application. </p> <p>NSOperationQueues have been refactored in recent OS versions to use GCD under the covers, so they are similarly efficient internally, although harder to use than GCD for most things.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload