Is there a way to unfreeze an object after it is r...
# kotlin-native
s
Is there a way to unfreeze an object after it is referenced by another thread? In my case I am capturing a property of some class in a lambda passed to a launch. The property is only read, never mutated by the coroutine. However, after the coroutine has executed, the property is frozen and can no longer be mutated by the object it belongs to. For example:
Copy code
class Foo {
   var bar = arrayOf(...)
}

var foo = Foo()
GlobalScope.launch {
    if (foo.bar.contains(...)) { ... }
}

// Once above coroutine is reached, any attempts to mutate foo.bar fail since it is frozen
I think I can achieve something similar with a
DetachedObjectGraph
but not sure how I would integrate that with my use case. Any example usages that might be helpful?
k
Sorry. Didn’t read that fully.
If you need to keep
bar
mutable, then you need to transfer it, which means
DetachedObjectGraph
, but this seems like a non-specific example. We never use
DetachedObjectGraph
in any production code. There’s usually a different way to architect things.