Removing memory mapped files in iOS - what's going on behind the scenes?

I have a file that has a memory card with NSData. Then I delete this file through NSFileManager without any errors and continue to verify that the file does not really exist (as far as NSFileManager and ls are concerned). However, I can still read data from the byte pointer that I received from NSData earlier!

In the simulator, I sometimes get seemingly unrelated crashes. Everything works fine on the device. I am very curious to know what is happening and what I should expect (what I expected in the past - either get an error message when trying to delete a file or crash when trying to access it after deleting it).

Thank!

+5
source share
1 answer

If you did not unlock the memory, then mmap, which you did with the file pointer, does not allow you to delete the file (although you do not see it). You should always unlock the memory before deleting the link file.

[This refers to the old UNIX trick - open the file as soon as you have the file descriptor, and then disconnect the file - you have a file with which you can do something, but no one can see, and if you completely destroy the file away!]

+6
source

All Articles