Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

to-dimension leaks activities! #59

Open
domokato opened this issue Jan 23, 2016 · 0 comments
Open

to-dimension leaks activities! #59

domokato opened this issue Jan 23, 2016 · 0 comments

Comments

@domokato
Copy link

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:

  1. Create two activities with relative-layouts or linear-layouts in them
  2. Use vector dimensions in the layout-width and/or layout-height
  3. Go back and forth between the activities
  4. 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:

  1. Use (.getApplicationContext (.getContext wdg)) instead in various parts in traits.clj.
  2. 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant