Closed toth-istvan-zoltan closed 18 hours ago
Without adding the gradient, everything is fine, there is no apparent memory leak.
Testing with Good Morning
for
cycle adds a new fragment).Ran for 3 hours without gradient, memory usage was between 47 MB and 52 MB after three hours.
Also did a few few minutes and compared memory graph instance numbers, no noticeable change in any categories.
After spending a lot of time on this, it seems like this is a rather hard issue to solve. There are quite a few posts about CALayer leaking memory.
https://youtrack.jetbrains.com/issue/KT-54805
I tries calling GC right after the I set the sublayers to null
. Nope, still leaks.
fragment.receiver.layer.sublayers = null
kotlin.native.runtime.GC.collect()
fragment.receiver.layer.sublayers?.forEach {
it as CALayer
it.removeFromSuperlayer()
}
kotlin.native.runtime.GC.collect()
Nope.
fragment.receiver.layer.sublayers?.forEach {
it as CALayer
it.removeFromSuperlayer()
it.delegate = null
it.removeAllAnimations()
}
kotlin.native.runtime.GC.collect()
Nope.
Figured it out, was a problem in reapplication of instructions.
Setting the colors for gradient is problematic because of memory management issues.
CFBridgingRelease
the gradient simply does not show.CFRetain
the app crashes withEXC_BAD_ACCESS
This code seems like working, but it leaks memory:
This code (from the YouTrack issue) crashes:
I'm not 100% sure that the problem is the colors or the CAGradientLayer. From the memory graph dump it seems like the gradient layer is not released.
Additional information: