This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Description
Providing a vector to :layout-height or :layout-width such as [10 :dp] leaks the Activity because eventually to-dimension is called with an Activity Context as a parameter ((.getContext wdg)), which then calls get-display-metrics if it gets a vector. get-display-metrics is memoized, so it keeps a reference to its parameter, the Activity, which then prevents the Activity from getting garbage collected after it finishes.
To reproduce:
- Create two activities with relative-layouts or linear-layouts in them
- Use vector dimensions in the layout-width and/or layout-height
- Go back and forth between the activities
- Use a memory profiler to view the memory usage, filter by the activity names
Result: You should see multiple instances of each activity kept in memory
Expected result: You should only see at most one instance of each activity
To fix, either:
- Use
(.getApplicationContext (.getContext wdg)) instead in various parts in traits.clj.
- Stop memoizing
get-display-metrics.
Note: For any users out there reading this, it remains safe to provide a vector to :text-size since it doesn't call to-dimension.
I'm using 3.2.0, but looking at the latest source the issue should still happen.