4

How many files can we safely keep open in an iOS application?

We are using FMOD to play audio in our game and apparently there a good strategy is to keep audio files pre-opened, but not loaded to memory, for rapid playback upon need.

I did not find information about either per-process limits not global system wide limits in Apple's documentation, here on SO, or anywhere else.

This quick test using a handy Python env on iPad suggests that the per-process limit is 250:

enter image description here

I think we stay below that limit. But we suspect that there is a rare problem situation where opening files fails.

Is there also a system wide limit that can affect at some point?

The per-app limit that I think I discovered with that test was asked in a comment in a related question but I can not comment there due to not having any reputation (first post): on iOS/iPhone: "Too many open files": need to list open files (like lsof)

EDIT:

The limits are easy to check on OSX like this. Perhaps possible also on a jailbroken iOS device, or somehow from an app using Apple's API / launching that system command?

Tonis-MacBook-Pro:MacOS antont$ sysctl kern.maxfilesperproc
kern.maxfilesperproc: 10240
Tonis-MacBook-Pro:MacOS antont$ sysctl kern.maxfiles
kern.maxfiles: 12288
Community
  • 1
  • 1
antont
  • 2,676
  • 1
  • 19
  • 21
  • I can support your claim on an iPad Air iOS 9.2. After **250** calls to `[(NSData *) writeToFile:options:error:]`, I get the following stuffed into my error object's `debugDescription`: `Error Domain=NSCocoaErrorDomain Code=512 "(null)" UserInfo={NSFilePath=..., NSUserStringVariant=Folder, NSUnderlyingError=0x15d6c47f0 {Error Domain=NSPOSIXErrorDomain Code=24 "Too many open files"}}` – ardnew Feb 11 '16 at 21:25
  • Can you please help to retrieve how to find how many files open in iPad @ardnew? Thanks – UserID0908 Oct 22 '18 at 13:42
  • How many in general or in your process? This question and answer are per process. – antont Oct 22 '18 at 18:42

1 Answers1

2

I happened to get an error saying:

Oct 7 15:24:08 iPhone-5 mobile_house_arrest[4354] : Max open files: 78

This stack overflow thread is also mentioning 78 as the number: mobile_house_arrest[xxx] <Error>: Max open files: 78

hence, it's possible that 78 is the number, however I don't have any 'official' source to confirm, as Apple docs for example.

Maximum amount of open files on iOS

Community
  • 1
  • 1
Cyryl Płotnicki
  • 473
  • 6
  • 12