How do I increase iOS open file limit?

We have "too many open files" exceptions" lately with our Xamarin forms iOS app. I tried to increase with setrlimit() but failed. It remains at limit of 256 file descriptors. I also tried using "ulimit -n 1024" in app option, Run|Custom Commands, as BeforeExecute command. The command didn't fail. But in our app, I still can open up to less than 250 files.

Any one has any idea about it? Thanks a lot in advance!


  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    Rather than trying to increase the limit, shouldn't you be figuring out why you have so many files open? You shouldn't need that many in any reasonable iOS scenario.

  • Thank you Dave Hunt! Other team members are trying to reduce # of open files (very difficult so far), and I am looking to increase open file limit for a possible solution.

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    There is no way to increase the limit.

  • Found this:

    It seems they found a solution there. But don't know how to set rlimit before start mono.

    Thanks again!

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    That bug doesn't apply to iOS. It was for a linux environment. A running process can't change it's own limits, so the workaround was to change the ulimit before starting the mono process. . There's no way to do anything like that in iOS.

  • Actually I tried, in XM code (iOS), setrlimit() to 1024 and getrlimit() got back with same value.So changing limit for process really works.

    It's only that mono init code call getrlimit() before main.cs, and cache/use that value thru out process life. setrlimit (ulimit) must be called before mono init code runs. That's how XM can do something with?

    XM can provide a way, when packaging iOS app, to specify a open file limit, and run ulimit with it, in same process, before mono init, whenever app runs.

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    Remember that iOS apps aren't like "normal" mono applications. Your code gets compiled into a native application. There is no separate mono process that starts your app.

    You'll have a much better chance of fixing your app so it doesn't need so many file handles than you will getting them to implement something like you're talking about.

    Really, there is no good reason for a mobile app to have that many files open at one time. It's most likely that you've got stray references to file wrappers that you aren't closing/disposing properly.

  • True. Thank you, DaveHunt:)

Sign In or Register to comment.