If I have a call, that is potentially leaking (no way of removing the listener)
g
gildor
04/09/2019, 3:06 AM
But you can remove listener, you can stop this task and listener will be removed
u
ursus
04/09/2019, 4:40 AM
how?? I cannot pass null, nor there is remoteXyz method
g
gildor
04/09/2019, 4:56 AM
Hah! Your right, you cannot cancel it, only if pass activity and it will be cancelled on lifecycle, sorry for confusion
what a garbage API
the only way to avoid leak is use weak reference than
or in case of activity pass activity as argument to addOnSuccessListener
u
ursus
04/09/2019, 5:38 AM
hm, Im not sure how weakref can work if the api requires concrete listener class? maybe pass hard reference but keep that as a weakref in the enclosing class?
Copy code
val ref = WeakReference( new listener )
FirebaseWhatevef.addOnSuccessListener(ref.get())
g
gildor
04/09/2019, 6:04 AM
no, I mean weakreference on objects inside of this listener, for example Emitter that used to deliver values to Rx