Search code examples
ktorkotlin-multiplatform

Can you create too many instances with Ktor


Coming from OkHttp if you created too many instances of the OkHttp client you would you would eventually get OutOfMemoryException from having too many clients created.

Is this also something that you would have to worry about when using Ktor?

I am trying to migrate from okhttp to ktor to support KMM and have only a little experience with Ktor


Solution

  • You can create as many HttpClient as you want, like you could do with OkHttp.

    It's up to you to make it singleton so that to have only one client instance.

    You can do it by yourself or use a DI library.