CFPreferences creates multiple files

I have only a small question:

Why is the CFPreferences-API creating multiple files in my UserPrefs-Directory? All files have their own Bundle-Identifier as a name, and all (except one, the original) added the following suffix:

  • com.myComp.myApp.plist <- (only this plist file should be created)
  • com.myComp.myApp.plist.0qzcicc
  • com.myComp.myApp.plist.8dhjfht
+4
source share
2 answers

This is very similar to the side effect of atomic writing.

Atomic recording means that whenever a file is to be written from an NSData object (or another), the file is first created using a temporary file name in the same directory. Then all data is written to this file (an operation that is usually not atomic). After closing the file, it is renamed to the original file name. Renaming is an atomic step that ensures that any other process that can look at a file sees either a complete old file or a complete new file. It is impossible for a process to see only half of the file.

Funny named files look like artifacts of this process. Maybe your application crashed in the middle of an atomic record?

+3
source

If you synchronize when you close the application, for example:

 - (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. } 

First, he will try to write to the dummy file and then perform atomic renaming. If the recording takes a long time, you will get a dummy file.

In my case, I had several users with 14mb plists and as a result there were a lot of dummy files (taking almost 2G).

My problem and fix was to compress the image I wrote for userdefaults.

0
source

All Articles