Repeatedly fetching recent document URLs causes Sandbox exceptions

Number:rdar://12245368 Date Originated:06-Sep-2012 02:06 PM
Status:Open Resolved:Duplicate
Product:Mac OS X Product Version:10.8.x
Classification: Reproducible:Always
Repeatedly calling [[NSDocumentController sharedDocumentController] recentDocumentURLs] in a sandboxed application project will eventually cause the following Console output:
06.09.12 09:58:36,544 TextEdit: Unable to consume sandbox extension for /Users/…/Library/Containers/;00000000;0000000000000020;;00000001;0e000002;000000000152baf8;/users/…/downloads/o11/text.txt): Cannot allocate memory

This message is printed for each document in the list of recently used documents and every time the method is called. In most cases, the output started at the 620th call to this method.
After these messages appear, the document cannot be saved to disk anymore.

The problem originally appeared in our application, but we were able to reproduce it on other sandboxed applications (e.g. the TextEdit sample project, see attached files).

The only workaround is to restart the application.

Steps to Reproduce:
1. Open the TextEdit sample project (version 1.7) that comes with Xcode.
2. Enable sandboxing for the project in the project settings, and set the "user selected file" option to "Read/Write Access".
3. In the "Document" class, add the following lines in the "init" Method:
        for (NSUInteger index = 0; index < 1000; index ++) {
                [[NSDocumentController sharedDocumentController] recentDocumentURLs];
                NSLog(@"%lu", index);
4. Open and close a few documents in TextEdit so that there are a number of recently used documents. 
5. After about 620 iterations, the above Console output should start appearing in the Console app. Saving the currently open document should fail.

Expected Results:
No Console output/sandbox exceptions no matter how many times the method [[NSDocumentController sharedDocumentController] recentDocumentURLs] is called. Document can be saved successfully. 

Actual Results:
Sandbox exceptions, Document cannot be saved.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!