8

I have a question from this stackoverflow question about iPhone storage. Like I already tried to answer, we can cache data in tmp directory. But a comment says that the data can be deleted when OS whimp. I don't understand exactly the problem that the comment says.

I want to ask if the process of OS deleting tmp directory is manually or automatically. In other words, if the system auto detect that our tmp directory has to be deleted.

Another question is that if we can control, or be asked to do something (before the deleting process) that can help us to keep the tmp directory.

Another question is that if we can not do anything then how often the OS will do that, under what circumstances

Community
  • 1
  • 1
vodkhang
  • 18,639
  • 11
  • 76
  • 110
  • 1
    This blog post explains about almost all directories of iOS application http://kmithi.blogspot.in/2012/08/ios-application-directory-structure.html –  Nov 15 '12 at 16:24

2 Answers2

26

The OS will delete the temp directory on restart and at other indeterminate points. If you need to store something somewhere that you don't want backed up then use the cache directory. That will not be deleted and will not be backed up.

Your application will not be running when the temp is deleted nor will you have an opportunity to react to that deletion. This is fairly common behavior on all unix based platforms (OS X does this as well).

Marcus S. Zarra
  • 46,571
  • 9
  • 101
  • 182
  • one more question is where I can store something that can be backed up and not be deleted as well – vodkhang Aug 30 '10 at 08:26
  • 4
    To be backed up and not deleted, it needs to be in the documents directory. – Marcus S. Zarra Aug 30 '10 at 12:27
  • Should be noted that in the iOS 5 world, the cache directory can now be cleaned out. So, not as reliable as it used to be. – ZaBlanc May 18 '12 at 19:14
  • That's maybe true for the system wide `/tmp` folder (which is not accessible by regular apps and not visible on a non-jailbroken phone). But local app `./tmp` folders *do not* get deleted when restarting iOS. – Ricardo Sanchez-Saez Jul 31 '14 at 14:59
  • Note that you can use *iExplorer* for having a look at app local `./tmp` directories on non-jailbroken phones. – Ricardo Sanchez-Saez Jul 31 '14 at 15:03
  • What do you mean by *intermediate points*? Also does this mean every app will load some objects from documents dir, some from cache directory and some from tmp directory-- all at once? – mfaani Apr 21 '16 at 17:35
  • I wrote *indeterminate points* not *intermediate points*. Different meaning entirely. What that means is that the OS is **not** locked into removing temp folders at a certain point in its lifecycle. It might remove them at *any* point and you need to be prepared for that. – Marcus S. Zarra Apr 21 '16 at 19:34
4

In iOS 5, OS can anytime clean cache and tmp directories. Only files in documents directory won't be deleted. These files will be also backed up to iCloud, so they shouldn't be big.

Here is great article about this issue: iOS 5 caches cleaning

Jercik
  • 71
  • 2
  • There is a fix for this issue in iOS 5.0.1. You can now specify which files should not be deleted during device cleanup. – BBonifield Nov 07 '11 at 18:38