https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
s

Stefan Oltmann

10/05/2023, 5:56 PM
I'm trying to understand the values I receive from the new Kotlin/Native GC on iOS. They don't seem to match what XCode memory report shows me.
kotlin.native.runtime.GC.lastGCInfo?.memoryUsageAfter?.get("heap")?.totalObjectsSizeBytes / 1024 / 1024
returns a value that's off by 10% to what XCode shows me. Isn't it supposed to be roughly the same? How can I determine the 1,9 GB shown in the screenshot? If that is reached low memory warnings are issued.
kotlin.native.runtime.GC.maxHeapBytes
is Long.MAX_VALUE without autotune and
kotlin.native.runtime.GC.targetHeapBytes
is constant 192 MB in my case. My background is that I want to adjust background work on images according to memory pressure.
l

Landry Norris

10/05/2023, 11:00 PM
Do you have any Swift/objective-c interop in your project or dependencies? The Kotlin GC will only track Kotlin objects. There will also be some overhead from the runtime, and I'd imagine the ram usage will count the copy of your app's binary stored in ram.
👍 1
s

Stefan Oltmann

10/06/2023, 5:31 AM
Good point. Yes, I have some interop and native libraries like Sentry. That’s a good explanation for the difference. That answers the first question. To the second question: How can I determine how much memory I can use?
l

Landry Norris

10/06/2023, 6:02 AM
I worked on a memory-constrained app at my last job. I remember there being a method on iOS that tells you how much ram your app has left. I remember it being 0 on simulator, though. I can see if I can find it in apple's docs.
👍 1
s

Stefan Oltmann

10/06/2023, 7:57 AM
I did not find it yet, but judging from number on StackOverflow taking half the physical memory as the upper limit (for crashes) should be a good estimation. I would love the system telling me exactly where the crash limit is.
NSProcessInfo.processInfo.physicalMemory.toLong() / 2