https://kotlinlang.org logo
#ktor
Title
# ktor
m

MrPowerGamerBR

01/12/2020, 6:33 PM
I'm not sure but... I think ktor client (Apache) is leaking TextContent objects for some reason? My app crashed and when looking at the memory dump there are 654 TextContent objects, in total they are using almost 4GBs (!) The engine is created with timeouts, so it isn't leaking because the connection never succeeds.
Copy code
this.socketTimeout = 25_000
			this.connectTimeout = 25_000
			this.connectionRequestTimeout = 25_000
YourKit shows that other ktor related classes are retaining a lot of memory, but I guess that's because it is retaining a lot of TextContents for some reason
kk maybe I found out the issue but I want to be sure: Do you need to manually
close()
all
HttpResponse
? That would explain why it is leaking memory
c

cy

01/12/2020, 7:10 PM
With ktor 1.2.x one SHOULD always close a response object!
d

Dico

01/12/2020, 7:26 PM
I guess they decided to start pooling stuff
m

MrPowerGamerBR

01/12/2020, 8:59 PM
Okay, thank you for helping @cy & @Dico, I didn't know you needed to close the HttpResponses ^-^ So I just need to do
httpResponse.close()
, right? The examples in the "Quick Start" section closes the entire client (in my case I have a global http client that the application uses) and the examples in the "Responses" sections doesn't mention that you need to close the response object. (maybe it would be nice to mention that there?)
a

Alexander Weickmann

06/17/2020, 3:16 PM
What if we use instead of a generic HttpResponse a custom type, like: client.put<CustomDataClass> Does the ktor client take care of closing the response stream?