Sam Schilling
09/06/2019, 4:38 PMfun elapsedRealtime() = (NSProcessInfo().systemUptime * 1_000)
val startTime = elapsedRealtime()
var currentTime = startTime
while (currentTime - startTime < 150) {
currentTime = elapsedRealTime()
}
I would think NSProcessInfo objects should automatically be deallocated each time elapsedRealtime
completes since the reference count would be 0, but I am unsure how Kotlin’s GC interacts with Swift/Objective-C’s ARC
If I change the loop to run for 25 seconds for example my memory usage shoots up nearly 500 MB.
This is running on macOS 10.14.6Sam Schilling
09/06/2019, 4:49 PMSam Schilling
09/06/2019, 4:50 PMfun elapsedRealTime() = autoreleasepool { NSProcessInfo().systemUptime * 1_000 }
In this case I can run for 25 seconds and only increase memory by about 7 MB (as opposed to 500 MB previously), but still that 7 MB never goes away after the factolonho
09/06/2019, 5:35 PM<https://github.com/JetBrains/kotlin-native/blob/8e0e346492436cc9c40d87f38926e841954d1d4e/runtime/src/main/kotlin/kotlin/native/internal/GC.kt#L30>
if you need to force collection, K/N uses delayed reference counter, so some memory may add upSam Schilling
09/06/2019, 6:22 PMSam Schilling
09/06/2019, 6:29 PMGC.start()
first since it says collect will not do anything if it is stoppedolonho
09/06/2019, 6:30 PMSam Schilling
09/06/2019, 6:31 PMSam Schilling
09/06/2019, 6:31 PMSam Schilling
09/06/2019, 6:35 PM@autoreleasepool content
section is never clearedSam Schilling
09/06/2019, 6:52 PMSam Schilling
09/06/2019, 7:29 PMGC.collect
after the loop body, memory usage grows very quickly, up to 500 MB:
while (currentTime - startTime < 25_000L) {
currentTime = timer.elapsedRealtime()
}
GC.collect()
Sam Schilling
09/06/2019, 7:30 PMwhile (currentTime - startTime < 25_000L) {
currentTime = timer.elapsedRealtime()
GC.collect()
}
Can anyone explain this disparity?Sam Schilling
09/06/2019, 7:30 PMSam Schilling
09/06/2019, 7:31 PMSam Schilling
09/06/2019, 7:35 PMolonho
09/07/2019, 8:08 AM