Note that there are some explanatory texts on larger screens.

plurals
  1. POsomething seems not to work as expected with @autoreleasepool
    primarykey
    data
    text
    <p>I have noted a very strange behaviour with @autoreleasepool.</p> <p>I have this method called by a timer on the main thread each "n" seconds. The method -simply speaking- create a copy of a large NSDictionary and saves it into a plist at a given path.</p> <p>So, the problem is that after each call to <code>[snapshot writeToFile:pathname atomically:YES];</code> the memory footprint of my app increases of about 5-6 MB, and it will not decrease even after exitig the <code>@autorelease</code> block.</p> <p>I cannot understand if the problem is with GCD, or @autoreleasepool, or writeToFileName:atomically:, or try/catch or if I did some mistake...</p> <p>...I'm driving crazy.</p> <p>Any suggestion?</p> <p>Thx in advance</p> <p>Rob</p> <pre><code>-(void)serializeIndexDictionary { if (_indexDictionary != nil &amp;&amp; _needsToSerialize == YES) { // save index dictionary dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ @autoreleasepool { @try { NSDate *start = [NSDate date]; NSString *pathname = [NSString stringWithFormat:@"%@/%@", _cacheBasePath, _cacheFilename]; // Per fare una copia ci mette zero-virgola mentre per salvare su file ci mette qualche secondo... // In questo modo la sezione critica dura molto meno... // ...e considerato che l'accesso all'indice blocca qualunque operazione, non mi pare cosa da poco. NSDictionary *snapshot = nil; @synchronized (self) { snapshot = [_indexDictionary copy]; _needsToSerialize = NO; } /* * If flag is YES, the dictionary is written to an auxiliary file, and then the auxiliary file is renamed to path. * If flag is NO, the dictionary is written directly to path. The YES option guarantees that path, if it exists at all, * --&gt; won’t be corrupted even if the system should crash during writing. &lt;-- */ [snapshot writeToFile:pathname atomically:YES]; snapshot = nil; NSFileManager *fileManager = [NSFileManager defaultManager]; [fileManager addSkipBackupAttributeToItemAtPath:pathname]; NSDictionary *attributes = [fileManager attributesOfItemAtPath:pathname error:nil]; unsigned long long fileSize = [attributes fileSize]; NSLog(@"%@: Index serialized (%lld bytes in %g seconds)", self, fileSize, [[NSDate date] timeIntervalSinceDate:start]); } @catch (NSException *exception) { NSString *message = [NSString stringWithFormat:@"%@: EXCEPTION CAUGHT\nDebug info:\n%@ (%@) [userInfo=%@]\n\nStack trace:\n%@", NSStringFromSelector(_cmd), exception.name, exception.reason, exception.userInfo, [exception callStackSymbols]]; NSLog(@"%@", message); } @finally { // noop } } }); } } </code></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.
    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