Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

Release resources onUnregisterObserver instead of onAbandon #29

Merged
merged 1 commit into from
Sep 5, 2016

Conversation

alexstyl
Copy link
Owner

@alexstyl alexstyl commented Sep 5, 2016

Description

LeakCanary is picking up some memeory leaks narrowing down that ContactsObserver was leaking the activity's context it is being used.

In com.alexstyl.specialdates:3.8:57.
* com.alexstyl.specialdates.ui.activity.MainActivity has leaked:
…

* GC ROOT android.database.ContentObserver$Transport.mContentObserver
* references com.alexstyl.specialdates.util.ContactsObserver$1.this$0 (anonymous class extends android.database.ContentObserver)
* references com.alexstyl.specialdates.util.ContactsObserver.callback
* references com.alexstyl.specialdates.upcoming.UpcomingEventsLoader$1.this$0 (anonymous class implements com.alexstyl.specialdates.util.ContactsObserver$Callback)
* references com.alexstyl.specialdates.upcoming.UpcomingEventsLoader.peopleEventsProvider
* references com.alexstyl.specialdates.service.PeopleEventsProvider.resolver
…

* references android.app.ContextImpl$ApplicationContentResolver.mContext
* references android.app.ContextImpl.mOuterContext
* leaks com.alexstyl.specialdates.ui.activity.MainActivity instance

as it turns out, the problem was not the Observer itself, but it was not being released in each of the Loaders it is being used. In this PR, all resources are released on the onUnregisterObserver() instead of onAbandon() which might not be called while dismissing the Loader

@alexstyl alexstyl merged commit 21b421d into develop Sep 5, 2016
@alexstyl alexstyl deleted the issues/leak branch September 5, 2016 22:40
@alexstyl alexstyl mentioned this pull request Sep 6, 2016
alexstyl added a commit that referenced this pull request Jul 4, 2020
Release resources onUnregisterObserver instead of onAbandon
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant