Note that there are some explanatory texts on larger screens.

plurals
  1. PORelease NSFileManager if it never reaches the release message
    primarykey
    data
    text
    <p>First off, I'd like to apologize in advance for not knowing this. I've been trying to get my head around the best way of dealing with memory management in this instance.</p> <p>I have a short method for determining if a file should be added to a list. One of the checks requires a NSFileManager be instantiated. Because some checks could potentially take a long time I want to jump out as soon as any of my conditions fail. However, if I return early my NSFileManager instance will never receive it's release message.</p> <p>I've thought about using an AutoReleasePool but since objects added to autoreleasepools don't get released until the end of the current run loop and my program looks over many thousands of files per run loop I don't like leaving them all allocated until the end of the loop.</p> <p>How can I ensure that each instance of my NSFileManager gets release appropriately. Any suggestions appreciated.</p> <p>Thanks!</p> <pre> - (BOOL) fileShouldBeAdded:(NSString *)filePath { BOOL fileShouldBeAdded = TRUE; NSFileManager *fileManager = [[NSFileManager alloc] init]; if ([[filePath lastPathComponent] containsString:@"test.txt"]) { fileShouldBeAdded = FALSE; return fileShouldBeAdded; } if (![fileManager xAttrFileAtPathShouldBeAdded:filePath]) { fileShouldBeAdded = FALSE; return fileShouldBeAdded; } if ([[BackupManager sharedInstance] isExcludedByUser:filePath]) { fileShouldBeAdded = FALSE; return fileShouldBeAdded; } if (![fileManager backupRequiredForPath:filePath]) { fileShouldBeAdded = FALSE; return fileShouldBeAdded; } [fileManager release]; return fileShouldBeAdded; } </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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