-
Notifications
You must be signed in to change notification settings - Fork 43
[v0.90.3] Memory leak #264
Description
I met the problem of memory leak with version 0.90.3 as following.
Simple code
val xmlSimpleStr = """
<person last-name="Doe">
<first-name>John</first-name>
</person>
""".trimIndent()
@Serializable
@XmlSerialName("person")
data class PersonSimple(
@XmlSerialName("first-name") @XmlElement(true) val firstName: String = "",
@XmlSerialName("last-name") @XmlElement(false) val lastName: String = "",
)
fun main() {
var res: PersonSimple? = null
repeat(5000000) {
res = XML { }
.decodeFromString(PersonSimple.serializer(), xmlSimpleStr)
}
println(res)
}
I find that if use
res = XML { }.decodeFromString(PersonSimple.serializer(), xmlSimpleStr)
I receive following exception after about 130_000 - 140_000 loops
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"
If use more complicated data classes, exception happen early, e.g. after 70_000 - 80_000 repetitions (even after 40_000 - 50_000 repetitions with some more "heavy" classes).
Suppose, it also can depend on PC and IDE memory settings
BUT!!!
If use code
res = XML.decodeFromString(PersonSimple.serializer(), xmlSimpleStr) // XML without { } !
no any exception, at lease after 5_000_000 repetitions
Also I find the same situation with some other decodeFromString/decodeFromReader function overloads - as soon as I use XML{ ... }, it cause OutOfMemory exception.
Note: of cause I used "repeat" loop only in this sample after I met the problem in my real code with other scenarios.