Shivam Kanodia
07/21/2023, 10:46 AMnavigation.pop()
it seems that the popped component is not released from memory as on popping the memory usage is not freed up, rather if i keep pushing and popping alternately memory usage keeps increasing in ios app.Arkadii Ivanov
07/21/2023, 10:48 AMArkadii Ivanov
07/21/2023, 10:49 AMShivam Kanodia
07/21/2023, 10:50 AMArkadii Ivanov
07/21/2023, 10:50 AMArkadii Ivanov
07/21/2023, 10:51 AMShivam Kanodia
07/21/2023, 10:52 AMArkadii Ivanov
07/21/2023, 10:55 AMArkadii Ivanov
07/21/2023, 10:55 AMShivam Kanodia
07/21/2023, 11:18 AMArkadii Ivanov
07/21/2023, 11:22 AMShivam Kanodia
07/21/2023, 11:25 AMShivam Kanodia
07/21/2023, 11:30 AMprivate fun onProjectListingOutput(output: ProjectListingComponent.Output): Unit =
when (output) {
is ProjectListingComponent.Output.NavigateBack -> navigation.pop()
is ProjectListingComponent.Output.NavigateToProjectDetails -> {
navigation.push(Configuration.ProjectDetails(projectId = output.projectId))
}
is ProjectListingComponent.Output.Logout -> {
navigation.replaceAll(Configuration.EnterMobileNumber)
}
is ProjectListingComponent.Output.NavigateToNotification -> {
foo()
// navigation.push(Configuration.Notification)
}
}
fun foo() {
val x = ByteArray(1000000)
println(x.size)
}
Shivam Kanodia
07/21/2023, 11:30 AMShivam Kanodia
07/21/2023, 11:30 AMArkadii Ivanov
07/21/2023, 11:32 AMShivam Kanodia
07/21/2023, 11:33 AMArkadii Ivanov
07/21/2023, 11:38 AMShivam Kanodia
07/21/2023, 11:43 AMArkadii Ivanov
07/21/2023, 11:49 AMArkadii Ivanov
07/21/2023, 11:50 AMShivam Kanodia
07/21/2023, 11:51 AMArkadii Ivanov
07/21/2023, 4:27 PMinternal expect fun Any.nativeDeallocChecker(): Any
In iosMain:
import kotlin.native.internal.createCleaner
@OptIn(ExperimentalStdlibApi::class)
internal actual fun Any.nativeDeallocChecker(): Any {
println("Allocated: $this")
return createCleaner(argument = this) { println("Deallocated: $it") }
}
Then inside a component class:
class DefaultSomeComponent : SomeComponent {
private val marker = listOf("Counter")
private val deallocChecker = marker.nativeDeallocChecker()
// The reset of the code
}
It is important that the checker must not reference the component itself, it should only reference the marker, otherwise it may not work. Once the component is deallocated, the marker object is also deallocated and the checker will print the message.
I have just checked on the Decompose sample, all DefaultCounterComponent
instances are deallocated eventually after pop. Not immediately, but eventually after some time. In my case it is ~10 seconds.Shivam Kanodia
07/21/2023, 5:54 PM