Does URLByResolvingBookmarkData consume any resources on iOS?

My app saves the file URLs obtained from UIDocumentPickerViewController as bookmark data and reads them on the "history screen".

In the "history screen", whenever viewWillAppear is called in ViewController, URLByResolveBookmarkData is called for all bookmarks to check if the file has been deleted or moved. (Please see code below)

- (void)refresh {
    NSManagedObjectContext* context = self.managedObjectContext;
    // read all bookmarks
    NSArray<HistoryItem*>* all = [self histories];
    
    [all enumerateObjectsUsingBlock:^(HistoryItem * _Nonnull item, NSUInteger idx, BOOL * _Nonnull stop) {
        
        BOOL isStale;
        NSURL* url = [NSURL URLByResolvingBookmarkData: item.bookmark
                                               options: 0
                                         relativeToURL: nil
                                   bookmarkDataIsStale: &isStale
                                                 error: nil];
        if(url == nil) {
            // file is deleted
            [context deleteObject: item];
        } else {
            item.filename = url.lastPathComponent;
            if(isStale) {
                // file is moved
                NSData *data = [url bookmarkDataWithOptions: 0
                             includingResourceValuesForKeys: 0
                                              relativeToURL: nil
                                                      error: nil];
                if(data != nil) {
                    item.bookmark = data;
                }
            }
        }
    }];
    
    [context save: nil];
}

Then, after many calls to viewWillAppear, calling startAccessingSecurityScopedResource on the URL obtained by URLByResolvingBookmarkData returns NO.

I suspect that URLByResolveBookmarkData is consuming some resources, because the problem reproduces even if I change the code inside the block to only call URLByResolveBookmarkData, and it doesn't reproduce when I empty the block.

Does URLByResolvingBookmarkData consume any resources? If so, how do I release the consumed resources?

OS: iOS 15 Xcode: 15.0

Then, after many calls to viewWillAppear, calling -startAccessingSecurityScopedResource on the URL

Are you sure you’re balancing each start with a matching call to -stopAccessingSecurityScopedResource?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Are you sure you’re balancing each start with a matching call to -stopAccessingSecurityScopedResource?

Yes. I always call stopAccessingSecurityScopedResource after calling startAccessingSecurityScopedResource and finishing using the file.

Additionally, this issue also occurs on the first call to startAccessingSecurityScopedResource after starting the app and calling URLByResolveBookmarkData many times.

OK.

I don’t really have a good answer for you here. I’ve looked at these issues a lot on macOS but the story is significantly different on iOS. If you really need an answer, I recommend that you open a DTS tech support incident and I, or more likely one of my colleagues, can allocate some time to look at it properly.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Does URLByResolvingBookmarkData consume any resources on iOS?
 
 
Q