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

to-dimension leaks activities! #59

@domokato

Description

@domokato

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions