Skip to content

MixpanelActivityLifecycleCallbacks leaks activities #463

Closed
@mindhacker42

Description

@mindhacker42

Library version: 5.1.0

LeakCanary trace:

In xxxxxxx.simpledemo:1.0:1.
* it.reveel.simpledemo.MainActivity has leaked:
* GC ROOT static it.reveel.sdk.internal.analytics.Analytics.mixpanelApi
* references com.mixpanel.android.mpmetrics.MixpanelAPI.mMixpanelActivityLifecycleCallbacks
* references com.mixpanel.android.mpmetrics.MixpanelActivityLifecycleCallbacks.check
* references com.mixpanel.android.mpmetrics.MixpanelActivityLifecycleCallbacks$1.val$activity (anonymous implementation of java.lang.Runnable)
* leaks xxxxxxx.simpledemo.MainActivity instance

* Retaining: 148 KB.
* Reference Key: 63546fe7-d0af-4992-a355-ca5a90e2ee4c
* Device: LGE google Nexus 5 hammerhead
* Android Version: 6.0.1 API: 23 LeakCanary: 1.5 00f37f5
* Durations: watch=5064ms, gc=130ms, heap dump=4808ms, analysis=236627ms

I looked at the code and I saw that you register for activity lifecycle callbacks to measure session duration and other stuff. You can disable other stuff but you can't disable measuring session duration.
Problem occurs when you capture activity object in Runnable and you retain that in variable and since MixpanelActivityLifecycleCallbacks lives forever in MixpanelAPI singleton that Runnable never gets GCed.

  1. It might help to unregister for lifecycle events in onResume or somewhere since you don't need to listen for that in background.
  2. Otherwise maybe putting "check" variable to null when removing callbacks from handler will also help.

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