Applications occasionally start showing "The document could not be autosaved" dialogs Every now and then, some application (usually TextEdit) starts showing dialogs like this when I try to close or save any document:


  The document “2.txt” could not be autosaved.
  
  Your changes will not be saved until the problem is resolved. You can also duplicate the document or discard your changes to close it.


I'll have to quit and reopen the application in order to save anything again.


I have disabled both Resume and locking files automatically in System Preferences
The files have usually been in normal folders under my home folder and there hasn't been anything special about them as far as I can tell
I have tried repairing permissions
TextEdit's code signature is valid


system.log usually has usually contained messages like this:

5/8/12 9:04:01.358 PM [0x0-0x17b17b].com.apple.TextEdit: [ERROR] GSLibrary.c:_AddGenerationInternal:393  Failed to consume sandbox extension; error 12 (Cannot allocate memory)
5/8/12 9:04:01.361 PM TextEdit: NSFileVersion tried to tried to add a new generation and failed. Versioned file URL: file://localhost/Users/lauri/Notes/2.txt, contents URL: file://localhost/Users/lauri/Notes/2.txt, error: Error Domain=GSLibraryErrorDomain Code=1 "The operation couldn’t be completed. (GSLibraryErrorDomain error 1.)" UserInfo=0x10b24d070 {}
5/8/12 9:04:01.362 PM TextEdit: NSDocument failed to preserve the old version of a document. Here's the error:
Error Domain=GSLibraryErrorDomain Code=1 "The operation couldn’t be completed. (GSLibraryErrorDomain error 1.)" UserInfo=0x10b24d070 {}


Failed to consume sandbox extension; error 12 (Cannot allocate memory)? Does anyone know what's going on here?

Edit: I haven't seen those errors after I replaced TextEdit with TextEditPlus. It's based on TextEdit's source code but it disables sandboxing and makes a few other changes.
It seems that this is actually a bug in Apple's sandboxing implementation. This means that none of the steps above should help. We had the same console output in one of our applications (including the inability to save text) and spent quite some time on finding the cause of the bug (see this radar). From what we've found out, it seems that after retrieving the recently opened documents for a number of times, the application cannot save files anymore because it does not get the permission to do so. You could try clearing the recently used documents menu, maybe this helps.