ursus
11/07/2018, 5:55 PMusing
?
contentObservable(resolver, uri, handler)
.flatMapSingle {
Single.fromCallable { resolver.query(uri, projection, selection, selectionArgs, sortOrder) }
}
.map<Optional<Contact>> { optionalOf(mapContact(it)) }
where that fromCallable returns Single<Cursor>, so obviously it will not close the cursor if stream gets unsubscribed after that and before mapContact where I actually close the cursor (now), therefore leaking the cursor right?artem_zin
11/08/2018, 5:06 AMCursor
being emitted
contentObservable(resolver, uri, handler)
.flatMapSingle {
resolver
.query(uri, projection, selection, selectionArgs, sortOrder)
.use {
it.let { mapContact(it) }
}
}
However, realistically, chances of situation when Cursor is emitted but stream disposed before Cursor was consumed is small and AbstractCursor
(which most Cursors extend) closes itself in its finalize
method, so while not perfect, it won’t leakursus
11/08/2018, 1:51 PMusing
, however its the same problem, first lambda takes should create the Cursor, then its all okay, but obviously if Cursor is coming from upstream, i.e. already was createdursus
11/08/2018, 1:52 PMartem_zin
11/08/2018, 4:13 PMursus
11/09/2018, 5:06 AMartem_zin
11/09/2018, 5:07 AMursus
11/09/2018, 5:09 AMursus
11/09/2018, 5:10 AMartem_zin
11/09/2018, 5:12 AMursus
11/09/2018, 5:13 AMartem_zin
11/09/2018, 5:14 AMursus
11/09/2018, 5:14 AMartem_zin
11/09/2018, 5:14 AMartem_zin
11/09/2018, 5:15 AMursus
11/09/2018, 5:16 AMartem_zin
11/09/2018, 5:16 AMursus
11/09/2018, 5:17 AMartem_zin
11/09/2018, 5:17 AMursus
11/09/2018, 5:17 AMartem_zin
11/09/2018, 5:17 AMursus
11/09/2018, 5:18 AMursus
11/09/2018, 5:18 AMartem_zin
11/09/2018, 5:19 AMursus
11/09/2018, 5:20 AMursus
11/09/2018, 5:20 AMartem_zin
11/09/2018, 5:25 AMartem_zin
11/09/2018, 5:25 AMursus
11/09/2018, 5:26 AMursus
11/09/2018, 5:26 AMartem_zin
11/09/2018, 5:27 AMartem_zin
11/09/2018, 5:28 AMartem_zin
11/09/2018, 5:28 AMartem_zin
11/09/2018, 5:29 AMursus
11/09/2018, 5:31 AMursus
11/09/2018, 5:32 AMursus
11/09/2018, 5:32 AMursus
11/09/2018, 5:33 AMartem_zin
11/09/2018, 5:38 AMursus
11/09/2018, 5:39 AMursus
11/09/2018, 5:39 AMartem_zin
11/09/2018, 6:15 AM