spierce7
03/26/2020, 8:39 PMStableRef
to allow a frozen
object to hold onto a non-frozen object, so that I can create an object that I can create a wrapping object that provides an interface that’s responsible for ensuring access on the right thread.
This creates a memory leak though, as StableRef
has to be `dispose`ed when it’s done.
Is there any way to get around disposing StableRef
so that I don’t have to add a dispose()
fun on every single one of these interfaces?
Is there another way to do this without using StableRef
?Dominaezzz
03/26/2020, 9:03 PMStableRef
across threads? That isn't supported behaviour. Objects have to be explicitly transferred.
You pretty much have to use DetachedObjectGraph
.Kris Wong
03/26/2020, 9:06 PMStableRef
Dominaezzz
03/26/2020, 9:07 PMDetachedObjectGraph
still has the issue of having to dispose it. It's not really possible to get around this issue because you are acquiring a strong reference dynamically.Kris Wong
03/26/2020, 9:09 PMAutoCloseable
if there needs to be any cleanupKris Wong
03/26/2020, 9:10 PMuse
themDominaezzz
03/26/2020, 9:10 PMAutoCloseable
now available on Native?spierce7
03/26/2020, 9:11 PMStableRef
across threads. I’m manually ensuring that I only access it on the correct thread.
private class AbTestRepositoryImpl : AbTestRepository {
private val delegate = StableRef.create(AbTestRepositoryBase())
init {
freeze()
}
override suspend fun getExperimentGroup(experimentName: String): String = withContext(dispatcher) {
delegate.get().getExperimentGroup(experimentName)
}
}
Kris Wong
03/26/2020, 9:11 PMspierce7
03/26/2020, 9:14 PMDominaezzz
03/26/2020, 9:14 PMspierce7
03/26/2020, 9:15 PMKris Wong
03/26/2020, 9:17 PMKris Wong
03/26/2020, 9:18 PMKris Wong
03/26/2020, 9:19 PMKris Wong
03/26/2020, 9:19 PMspierce7
03/26/2020, 9:28 PMKris Wong
03/26/2020, 9:31 PMThreadedAccessor
, which could be frozen, and it send messages to a Channel
spierce7
03/26/2020, 9:31 PMfrozen
, but I don’t want the delegate that it uses to be frozen. I want that to be able to access state without having to use atomics
because the wrapping interface ensures that it’s only ever touched by a single thread.spierce7
03/26/2020, 9:32 PMKris Wong
03/26/2020, 9:33 PMKris Wong
03/26/2020, 9:33 PMspierce7
03/26/2020, 9:34 PMdispose
method? That’d be pretty crappy.Kris Wong
03/26/2020, 9:36 PMKris Wong
03/26/2020, 9:39 PMspierce7
03/26/2020, 10:15 PMspierce7
03/26/2020, 10:15 PM