I'm having what may be an apple-specific issue wit...
# kotlin-native
s
I'm having what may be an apple-specific issue with trying to use the runtime GC to look for memory leaks in a unit test. Given a kotlin unit test function like this:
Copy code
import kotlin.native.runtime.GC

...

runTest {
    GC.collect()
    val startMemory = GC.lastGCInfo!!.memoryUsageAfter["heap"]?.totalObjectsSizeButes
	
    << some test code here>>

    GC.collect()
}
Running the above in the IOSX64 simulator results in the "some test code here" block working fine. The
startMemory
variable gets a valid value (approx. 8.9mb). However on the second
GC.collect()
invoke, this happens:
Copy code
Child process terminated with signal 6: Abort trap
If I comment out the second invocation of
GC.collect()
, the unit test succeeds. Does the Abort trap mean the second
GC.collect()
is throwing an uncaught apple exception? If so is this a bug, or a feature in
GC.collect()
? My intent was to get the heap size in bytes again after the second call and assert that start and end heap sizes are equal, but this abort trap prevents that. And I don't know how (if there is a way) in native kotlin code to catch an Apple exception. Wrapping the
GC.collect()
in a try/catch block does not affect the outcome, so it is not an uncaught Kotlin native exception. For any info on what I'm doing wrong or other help, thanks in advance. Environment is MacOS, Kotlin 1.9.23