Deleting a folder with a large number of files on iOS

Let's say I have a folder in the iOS application data directory with several thousand small files. Removing this folder (via [NSFileManager removeItemAtPath]) takes a non-trivial amount of time. But in OS X, deleting a folder with the same content happens very quickly. It seems to just detach the folder from the file system. So why is iOS taking so long? What is the difference?

Edit: On iPad 3, deleting 3 folders from 5,000 to 9,000 files takes about 35 seconds. A simulator running on an earlier Retina MBP takes about 1.5 seconds.

+4
source share
3 answers

, , "" - , . - .

: Mac - - (3,5 ") , , . , HFS.

/ , .

, Cocoa. (/)" " (/) (" "(/)).

, " ". , " dealloc'ed ".

(/) , " ". " " - " " .

:

" - , . ,    .

, - , . "" . "", . "" , .

"" "" !

- - , . , OSX .

.

iOS

[NSFileManager removeItemAtPath: error:], , . . , , . ?

,

  • , , , ( ), .

  • , , .

+4

Mac, , Mac.
, iphone , Mac.
, , - .
?

0

. , .

- (void) deleteDocumentsDirectoryContents
{
    NSString *folderPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSError *error = nil;
    for (NSString *file in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:folderPath error:&error])
    {
        [[NSFileManager defaultManager] removeItemAtPath:[folderPath stringByAppendingPathComponent:file] error:&error];
    }
}

.

[self performSelectorInBackground:@selector(deleteDocumentsDirectoryContents) withObject:nil];
0

Source: https://habr.com/ru/post/1529446/


All Articles