我只有一个小问题:
为什么CFPreferences-API在我的UserPrefs-Directory中创建多个文件?所有文件都以my标识符作为名称,所有文件(除了原始文件)都添加了如下后缀:
)
发布于 2010-03-18 09:00:12
这看起来很像原子书写的副作用。
原子写入意味着,每当要从NSData (或其他)对象写入文件时,首先使用同一个目录中的临时文件名创建该文件。然后将所有数据写入该文件(通常不是原子操作)。关闭文件后,它将被重命名为原始文件名。重命名是一个原子步骤,它确保可能查看该文件的任何其他进程都可以看到完整的旧文件或完整的新文件。进程不可能只看到文件的一半。
有趣的命名文件看起来像是这个过程中的工件。也许你的应用程序在原子写的过程中崩溃了?
发布于 2015-03-16 15:10:08
例如,如果您在关闭应用程序时进行同步:
- (void)applicationWillResignActive:(UIApplication *)application
{
[[NSUserDefaults standardUserDefaults] synchronize];
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}它将尝试首先写入虚拟文件,然后执行原子重命名。如果写得太长,你就会得到一个假文件。
在我的例子中,我有一些有14mb plist的用户,最终有很多虚拟文件(几乎是2G)。
我的问题和修正是压缩我写到用户默认值的图像。
https://stackoverflow.com/questions/2468403
复制相似问题