Hi. We use Ui tests for memory leaks detektion. But we've found leak at IndexMatcher that was added in https://github.com/agoda-com/Kakao/pull/200/files
The IndexMatcher contains link on a View and create memory leak when we leave Activity/Fragment in test step.
To reproduce:
Create any screen with using of ViewBuilder.withIndex
class TestScreen : Screen<TestScreen>() {
val testView = KView {
withIndex(0) {
...
}
}
}
Open some TestActivity/TestFragmen.
Use testView in test step.
Close that TestActivity/TestFragmen.
Result:
E/TestRunner: ----- begin exception -----
E/TestRunner: leakcanary.NoLeakAssertionFailedError: Application memory leaks were detected:
E/TestRunner: ====================================
E/TestRunner: HEAP ANALYSIS RESULT
E/TestRunner: ====================================
E/TestRunner: 1 APPLICATION LEAKS
E/TestRunner: References underlined with "~~~" are likely causes.
E/TestRunner: Learn more at https://squ.re/leaks.
E/TestRunner: 12136 bytes retained by leaking objects
E/TestRunner: Displaying only 1 leak trace out of 3 with the same signature
E/TestRunner: Signature: c7099d19e12c64f391b6157a00d3e14c2eed18a7
E/TestRunner: ┬──�
E/TestRunner: ��
E/TestRunner: │ GC Root: Input or output parameters in native code
E/TestRunner: │
E/TestRunner: ├─ com.project.android.test.mock.valuation.FlatValuationUiTest instance
E/TestRunner: │ Leaking: UNKNOWN
E/TestRunner: │ Retaining 1,5 MB in 24968 objects
E/TestRunner: │ ↓ FlatValuationUiTest.valuationScreen
E/TestRunner: │ ~~~~~~~~~~~~~~~
E/TestRunner: ├─ com.project.android.screens.FlatValuationScreen instance
E/TestRunner: │ Leaking: UNKNOWN
E/TestRunner: │ Retaining 1,5 MB in 24965 objects
E/TestRunner: │ ↓ FlatValuationScreen.salePriceView
E/TestRunner: │ ~~~~~~~~~~~~~
E/TestRunner: ├─ io.github.kakaocup.kakao.text.KTextView instance
E/TestRunner: │ Leaking: UNKNOWN
E/TestRunner: │ Retaining 1,4 MB in 24432 objects
E/TestRunner: │ ↓ KBaseView.view
E/TestRunner: │ ~~~~
E/TestRunner: ├─ io.github.kakaocup.kakao.delegate.ViewInteractionDelegate instance
E/TestRunner: │ Leaking: UNKNOWN
E/TestRunner: │ Retaining 1,4 MB in 24431 objects
E/TestRunner: │ ↓ ViewInteractionDelegate.interaction
E/TestRunner: │ ~~~~~~~~~~~
E/TestRunner: ├─ androidx.test.espresso.ViewInteraction instance
E/TestRunner: │ Leaking: UNKNOWN
E/TestRunner: │ Retaining 1,4 MB in 24430 objects
E/TestRunner: │ ↓ ViewInteraction.viewMatcher
E/TestRunner: │ ~~~~~~~~~~~
E/TestRunner: ├─ org.hamcrest.core.AllOf instance
E/TestRunner: │ Leaking: UNKNOWN
E/TestRunner: │ Retaining 1,4 MB in 24418 objects
E/TestRunner: │ ↓ AllOf.matchers
E/TestRunner: │ ~~~~~~~~
E/TestRunner: ├─ java.util.ArrayList instance
E/TestRunner: │ Leaking: UNKNOWN
E/TestRunner: │ Retaining 1,4 MB in 24417 objects
E/TestRunner: │ ↓ ArrayList[0]
E/TestRunner: │ ~~~
E/TestRunner: ├─ io.github.kakaocup.kakao.common.matchers.IndexMatcher instance
E/TestRunner: │ Leaking: UNKNOWN
E/TestRunner: │ Retaining 1,4 MB in 24415 objects
E/TestRunner: │ ↓ IndexMatcher.seen
E/TestRunner: │ ~~~~
E/TestRunner: ├─ java.util.LinkedHashSet instance
E/TestRunner: │ Leaking: UNKNOWN
E/TestRunner: │ Retaining 1,4 MB in 24407 objects
E/TestRunner: │ ↓ LinkedHashSet[element()]
E/TestRunner: │ ~~~~~~~~~~~
E/TestRunner: ╰→ android.widget.LinearLayout instance
E/TestRunner: ​ Leaking: YES (ObjectWatcher was watching this because com.project.valuation.ui.screen.flat.FlatValuationFragment received Fragment#onDestroyView() callback (references to its views should be cleared to prevent leaks) and View.mContext references a destroyed activity)
E/TestRunner: ​ Retaining 2,1 kB in 52 objects
E/TestRunner: ​ key = ea5d88bb-8313-47b4-b590-24555ab2b30a
E/TestRunner: ​ watchDurationMillis = 6078
E/TestRunner: ​ retainedDurationMillis = 1078
E/TestRunner: ​ View not part of a window view hierarchy
E/TestRunner: ​ View.mAttachInfo is null (view detached)
E/TestRunner: ​ View.mWindowAttachCount = 1
E/TestRunner: ​ mContext instance of com.project.valuation.ui.screen.flat.FlatValuationActivity with mDestroyed = true
Hi. We use Ui tests for memory leaks detektion. But we've found leak at IndexMatcher that was added in https://github.com/agoda-com/Kakao/pull/200/files The
IndexMatcher
contains link on aView
and create memory leak when we leave Activity/Fragment in test step.To reproduce:
screen
with using ofViewBuilder.withIndex
testView
in test step.Result: