Skip to content

Fix memory leak when prompt isn't explicitly dismissed#113

Merged
sjwall merged 2 commits intosjwall:masterfrom
SUPERCILEX:leak
May 5, 2018
Merged

Fix memory leak when prompt isn't explicitly dismissed#113
sjwall merged 2 commits intosjwall:masterfrom
SUPERCILEX:leak

Conversation

@SUPERCILEX
Copy link
Copy Markdown
Contributor

@SUPERCILEX SUPERCILEX commented Apr 28, 2018

The animation listener doesn't die with the view apparently (which leaks it).

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2018

Codecov Report

Merging #113 into master will decrease coverage by 0.26%.
The diff coverage is 25%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #113      +/-   ##
============================================
- Coverage     95.88%   95.62%   -0.27%     
  Complexity      334      334              
============================================
  Files            14       14              
  Lines          1070     1074       +4     
  Branches        125      125              
============================================
+ Hits           1026     1027       +1     
- Misses           21       24       +3     
  Partials         23       23
Impacted Files Coverage Δ Complexity Δ
...terialtaptargetprompt/MaterialTapTargetPrompt.java 89.39% <25%> (-0.8%) 44 <0> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e687c56...28f5668. Read the comment docs.

protected void onDetachedFromWindow()
{
super.onDetachedFromWindow();
mPrompt.cleanUpAnimation();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that this isn't a call to cleanUpPrompt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanUpPrompt also notifies state changes which seems like we'd be introducing a race condition... I just realized I didn't share the leak with you, it's just the animator stuff which is leaking:

In com.supercilex.robotscouter.debug:2.3.1-DEBUG:1.
* com.supercilex.robotscouter.HomeActivity has leaked:
* GC ROOT android.widget.Toast$TN.mNextView
* references android.widget.LinearLayout.mParent
* references android.view.ViewRootImpl.mChoreographer
* references android.view.Choreographer.mCallbackQueues
* references array android.view.Choreographer$CallbackQueue[].[1]
* references android.view.Choreographer$CallbackQueue.mHead
* references android.view.Choreographer$CallbackRecord.action
* references android.animation.AnimationHandler$1.this$0 (anonymous implementation of android.view.Choreographer$FrameCallback)
* references android.animation.AnimationHandler.mAnimationCallbacks
* references java.util.ArrayList.elementData
* references array java.lang.Object[].[0]
* references android.animation.ValueAnimator.mUpdateListeners
* references java.util.ArrayList.elementData
* references array java.lang.Object[].[0]
* references uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt$10.this$0 (anonymous implementation of android.animation.ValueAnimator$AnimatorUpdateListener)
* references uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.mView
* references uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt$PromptView.mContext
* leaks com.supercilex.robotscouter.HomeActivity instance

* Retaining: 6.5 kB.
* Reference Key: 8200773e-a087-4f54-8dd7-9fe208a43681
* Device: Google google Pixel 2 XL taimen
* Android Version: 8.1.0 API: 27 LeakCanary: 1.5.4 74837f0
* Durations: watch=5315ms, gc=172ms, heap dump=1438ms, analysis=154338ms

{
final ResourceFinder resourceFinder = promptOptions.getResourceFinder();
mView = new PromptView(resourceFinder.getContext());
mView.mPrompt = this;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this reference be set to null in cleanUpPrompt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can, but it isn't necessary. The issue is the prompt holding on to the view, not the other way around.

@sjwall sjwall merged commit f72dfae into sjwall:master May 5, 2018
@sjwall
Copy link
Copy Markdown
Owner

sjwall commented May 5, 2018

Thanks again for your work and supplying the memory leak info

@SUPERCILEX SUPERCILEX deleted the leak branch May 5, 2018 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants