Search code examples
iossqlitememorycore-datansfilemanager

Does NSFileManager's moveItemAtPath:toPath:error method load the file being moved into memory?


I move each user's .sqlite database to a different directory in my latest app update. I was using the Core Data method migratePersistentStore:toURL:options:withType:error, and some users' apps were shutting down because of the excessive amount of memory used. So I am reverting to NSFileManager's moveItemAtPath:toPath:error method. I don't believe that that loads the database into memory the same way that migratePersistentStore:toURL:options:withType:error does, but I am concerned that moving a very large database could still present the same memory issues. I could use some advice - does anyone know for sure if a file is or is not loaded into memory when it is moved? Is there a way to move a VERY large file in a way that is respectful of device memory? Is there a better method than moveItemAtPath:toPath:error available for this?


Solution

  • I agree with you that moving with NSFileManager should only change the linking in the file system and would not load anything into memory. But if you really want to know for sure, don't trust an answer that you get on Stack Overflow, test it yourself, in your app! While running your app under Xcode, click the Debug Navigator, then the Show Debug Gauges tool, then Memory. It looks very pretty.

    enter image description here

    Then test one of your file moves and verify that there is no memory spike.