Kotlin/Native: Is CValue<T>.useContents dangerous?

Viewed 25

In this paragraph it states that useContents "temporarily places the CValue to memory, and then runs the passed lambda with this placed value T as receiver".

A few questions about this:

  1. Since this implies that T is not in memory at this moment, is there a risk that useContents fails because the value no longer available?
  2. What happens if I do this: val foo = bar.useContents { this }. Does this copy T? Is it now in memory permanently? Do I need to clean it up manually somehow?
  3. Why is this even necessary? Can't the compiler take care of these details? I just end up writing a lot of extension functions to hide useContents.
0 Answers
Related