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

Landry Norris

06/30/2022, 4:38 PM
How does the kotlin.native.internal.GC class work when I’m on the new memory model? The comments indicate that it controls the old ARC-like GC. I’m getting memory leaks in my app right now while interoping with a C library, so I’m mixing Kotlin’s GC with manual malloc/free. I’d like to be able to force a GC periodically so I can see the memory impact of my malloc/free objects. Edit: Adding GC.start() before seemed to force a GC. I now see a sharp drop in memory usage immediately.
2
I see no change in memory when I call GC.collect(). If I let the code run longer, however, I can see the memory suddenly drop periodically, indicating a GC cycle. My code is running in a loop, so the objects in use by the Kotlin memory model should be consistent at the end of any given loop iteration.
After getting the GC to trigger, I verified that the leak is something that I allocate from the C library, not an object in my Kotlin code. Guess I’ll have to brush up on valgrind 😬
a

andylamax

06/30/2022, 9:54 PM
Thanks to this post. Noe I know about GC.start() and GC.collect()
11 Views