Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround to open file handles for loaded assets (#1287)
We ran into an issue that our production app was crashing on certain devices as we opened too many file descriptors (> 256). See some details here: https://wilsonmar.github.io/maximum-limits/ We found that macOS will keep image files handles open for `NSImage` lifetime in some cases: ``` // this will keep file open only if image is loaded from app bundle NSString *path = [[NSBundle mainBundle] pathForResource:@"slider" ofType:@"png" inDirectory:@"assets"]; _image = [[NSImage alloc] initWithContentsOfFile:path]; // this will not keep file open _image = [[NSImage alloc] initWithContentsOfFile:@"/Users/theUser/Downloads/slider.png"]; // this will not keep file open NSData *data = [NSData dataWithContentsOfFile:path]; _image = [[NSImage alloc] initWithData:data]; ``` This can be documented behavior, but I didn't find any reference in documentation or headers. Test Plan: - build and run prod version of app - explore open files for Messenger process in Activity Monitor - confirm no assets are open Co-authored-by: Scott Kyle <skyle@fb.com>
- Loading branch information