Skip to content

[v0.90.3] Memory leak #264

@Leycaron

Description

@Leycaron

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    indevThe issue is fixed/implemented in the dev branch

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions