ios - 我们是否应该避免手动清除 iOS tmp 和 Caches 文件夹?

标签 ios

Use this directory to write temporary files that do not need to persist between launches of your app. Your app should remove files from this directory when they are no longer needed; however, the system may purge this directory when your app is not running.

https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html



关于是否需要手动清除 tmp 存在相互矛盾的答案。文件夹。没有用于清除它的 API,必须逐个文件手动执行(这说明了一些事情)。更重要的是,我们应该始终避免不必要地过度使用磁盘,因为它会磨损 SSD(Apple 的数据存储指南也提到了这一点),并且按设计为由操作系统定期清除的文件逐个清除文件夹文件似乎违反直觉。
  • 那么删除我们确定不再需要的内容(现场清洁)并让操作系统清除其余部分并完全避免手动清除,这不是最佳做法吗?
  • 我们是否应该将此策略应用于 Library/Caches文件夹也是如此,因为该文件夹的清理策略与 tmp 相同。文件夹的?
  • 最佳答案

    你说:

    1. Would it not be best practice then to delete what we know for certain isn't needed anymore as it comes our way (on-the-spot cleaning) and let the rest be purged by the OS and avoid manual purging altogether?


    是的,文档告诉你,当你创建一个临时文件时,你应该在完成后立即删除它。不需要“手动清除”或清扫此文件夹。完成后只需删除单个文件即可。

    1. And should we not apply this strategy to the Library/Caches folder as well, since that folder's cleaning policy is the same as the tmp folder’s?


    如果您确定不再需要特定的缓存文件,那么绝对删除它。

    但通常使用缓存时,您不知道何时不再需要特定文件,因此我们经常根据 Assets 的数量、大小或成本求助于 LRU 风格的逻辑。

    但在这两种情况下,都需要酌情清理,以防止存储空间无节制地增长。您希望避免对不再需要的 Assets 使用持久存储

    关于ios - 我们是否应该避免手动清除 iOS tmp 和 Caches 文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61823482/

    相关文章:

    ios - 使用按钮执行一段代码几秒/分钟?

    ios - 在 HTTPS 主机的情况下创建多个 NSURLSession 对象

    android - 更改了 jQuery Mobile 的默认图标集,在浏览器上工作,在设备上失败

    ios - 对 NSDictionary 进行降序排序。如何使用 `compare:options:` 选择器发送选项?

    ios - 解析 + Facebook 问题

    iOS Core Data NSFetchedResultController.fetchedObject 返回错误数据和 (0,0) 注解

    ios - 呈现和关闭模态视图 Controller

    ios - 在 iOS 的 Google Maps SDK 中启用方向

    objective-c - iOS - 从 willEnterForeground 的 UIViewController 执行选择器

    ios - 使用 ARC GPUImage 的内存泄漏