AnyChart / AnyChart-Android

AnyChart Android Chart is an amazing data visualization library for easily creating interactive charts in Android apps. It runs on API 19+ (Android 4.4) and features dozens of built-in chart types.
2.29k stars 367 forks source link

APIlib is leaking AnyChartView #190

Open pyricau opened 4 years ago

pyricau commented 4 years ago

This issue was found through StackOverflow.

Here's the leaktrace:

    ┬───
    │ GC Root: System class
    │
    ├─ com.anychart.APIlib class
    │    Leaking: NO (a class is never leaking)
    │    ↓ static APIlib.instance
    │                    ~~~~~~~~
    ├─ com.anychart.APIlib instance
    │    Leaking: UNKNOWN
    │    ↓ APIlib.anyChartView
    │             ~~~~~~~~~~~~
    ├─ com.anychart.AnyChartView instance
    │    Leaking: YES (View.mContext references a destroyed activity)
    │    mContext instance of com.dreamakers.clustore.clustorestore.Activity.AnalyticsActivity with mDestroyed = true
    │    View#mParent is set
    │    View#mAttachInfo is null (view detached)
    │    View.mID = R.id.any_chart_view
    │    View.mWindowAttachCount = 1
    │    ↓ AnyChartView.mContext
    ╰→ com.dreamakers.clustore.clustorestore.Activity.AnalyticsActivity instance
    ​     Leaking: YES (ObjectWatcher was watching this because com.dreamakers.clustore.clustorestore.Activity.AnalyticsActivity received Activity#onDestroy() callback and Activity#mDestroyed is true)
    ​     key = 7ac56641-d049-41a3-8cb8-0a2cae7cc320
    ​     watchDurationMillis = 8099
    ​     retainedDurationMillis = 3098

AnyChartView.init() passes the AnyChartView instance to APIlib.getInstance().setActiveAnyChartView(this); (source). APIlib is a singleton that is never cleared from memory, so it holds the AnyChartView forever, which in turns holds the activity context as well as the whole view hierarchy.

Shestac92 commented 4 years ago

@pyricau Thank you for your report! We will take into account for future updates.