@@ -681,43 +681,47 @@ - (NSNumber *)_numberForEntryAtIndex:(NSInteger)index {
681681#pragma mark - Working with Metadata
682682
683683- (void )saveMetadata {
684- [_lock lock ];
685-
686- NSDictionary *metadataDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
687- [_indexMap copy ], FICImageTableIndexMapKey,
688- [_sourceImageMap copy ], FICImageTableContextMapKey,
689- [[_MRUEntries array ] copy ], FICImageTableMRUArrayKey,
690- [_imageFormatDictionary copy ], FICImageTableFormatKey, nil ];
684+ @autoreleasepool {
685+ [_lock lock ];
686+
687+ NSDictionary *metadataDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
688+ [_indexMap copy ], FICImageTableIndexMapKey,
689+ [_sourceImageMap copy ], FICImageTableContextMapKey,
690+ [[_MRUEntries array ] copy ], FICImageTableMRUArrayKey,
691+ [_imageFormatDictionary copy ], FICImageTableFormatKey, nil ];
691692
692- __block int32_t metadataVersion = OSAtomicIncrement32 (&_metadataVersion);
693+ __block int32_t metadataVersion = OSAtomicIncrement32 (&_metadataVersion);
693694
694- [_lock unlock ];
695-
696- static dispatch_queue_t __metadataQueue = nil ;
697- static dispatch_once_t onceToken;
698- dispatch_once (&onceToken, ^{
699- __metadataQueue = dispatch_queue_create (" com.path.FastImageCache.ImageTableMetadataQueue" , NULL );
700- });
701-
702- dispatch_async (__metadataQueue, ^{
703- // Cancel serialization if a new metadata version is queued to be saved
704- if (metadataVersion != _metadataVersion) {
705- return ;
706- }
695+ [_lock unlock ];
696+
697+ static dispatch_queue_t __metadataQueue = nil ;
698+ static dispatch_once_t onceToken;
699+ dispatch_once (&onceToken, ^{
700+ __metadataQueue = dispatch_queue_create (" com.path.FastImageCache.ImageTableMetadataQueue" , NULL );
701+ });
702+
703+ dispatch_async (__metadataQueue, ^{
704+ // Cancel serialization if a new metadata version is queued to be saved
705+ if (metadataVersion != _metadataVersion) {
706+ return ;
707+ }
707708
708- NSData *data = [NSJSONSerialization dataWithJSONObject: metadataDictionary options: kNilOptions error: NULL ];
709+ @autoreleasepool {
710+ NSData *data = [NSJSONSerialization dataWithJSONObject: metadataDictionary options: kNilOptions error: NULL ];
709711
710- // Cancel disk writing if a new metadata version is queued to be saved
711- if (metadataVersion != _metadataVersion) {
712- return ;
713- }
712+ // Cancel disk writing if a new metadata version is queued to be saved
713+ if (metadataVersion != _metadataVersion) {
714+ return ;
715+ }
714716
715- BOOL fileWriteResult = [data writeToFile: [self metadataFilePath ] atomically: NO ];
716- if (fileWriteResult == NO ) {
717- NSString *message = [NSString stringWithFormat: @" *** FIC Error: %s couldn't write metadata for format %@ " , __PRETTY_FUNCTION__, [_imageFormat name ]];
718- [self .imageCache _logMessage: message];
719- }
720- });
717+ BOOL fileWriteResult = [data writeToFile: [self metadataFilePath ] atomically: NO ];
718+ if (fileWriteResult == NO ) {
719+ NSString *message = [NSString stringWithFormat: @" *** FIC Error: %s couldn't write metadata for format %@ " , __PRETTY_FUNCTION__, [_imageFormat name ]];
720+ [self .imageCache _logMessage: message];
721+ }
722+ }
723+ });
724+ }
721725}
722726
723727- (void )_loadMetadata {
0 commit comments