Memory leaks in BlockingBlurController
See original GitHub issueHello, @Dimezis
I’m using your librray in such way: Activity -> Fragment -> RecyclerView Item with blurred background. So, when I replace fragment with recyclerview and blured items to another one I’m getting several leaks detected by LeakCanary.
screenshot #1 screenshot #2 screenshot #3
In my (and LeakCanary’s) opinion the leak was caused by anonymous class in BlockingBlurController#deferBitmapCreation (read here about it)
I tried to remove it at all and as result no leaks detected and lower memory consumption achieved. So I can suggest to make that class static.
private static class SizeHandler implements ViewTreeObserver.OnGlobalLayoutListener {
private WeakReference<View> blurView;
private SizeHandlerListener listener;
SizeHandler(View blurView, SizeHandlerListener listener) {
this.blurView = new WeakReference<>(blurView);
this.listener = listener;
}
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
blurView.get().getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
legacyRemoveOnGlobalLayoutListener();
}
int measuredWidth = blurView.get().getMeasuredWidth();
int measuredHeight = blurView.get().getMeasuredHeight();
listener.onSizeClarified(measuredWidth, measuredHeight);
}
@SuppressWarnings("deprecation")
void legacyRemoveOnGlobalLayoutListener() {
blurView.get().getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
private interface SizeHandlerListener {
void onSizeClarified(int measuredWidth, int measuredHeight);
}
And call it from function like it:
private void deferBitmapCreation() {
new SizeHandler(blurView, this::init);
}
This solution fixed memory leak for me.
Regards, Alexey Egin.
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (9 by maintainers)
Top Results From Across the Web
Solving Memory Leaks with React Native - Enquero
In essence, memory leaks can be defined as memory that is not required by an application anymore that for some reason is not...
Read more >Understanding Memory Leaks in Java - Baeldung
A memory leak is bad because it blocks memory resources and degrades system performance over time.
Read more >Hunting JS memory leaks in React Native apps
1 reason for memory leaks in React apps in general. Let's look at the following component that listens to keyboard showing and hiding...
Read more >How to Detect Memory Leaks in Java: Causes, Types, & Tools
Memory leaks block access to resources and cause an application to consume more memory over time, leading to degrading system performance. If ......
Read more >Memory Leaks, How to avoid them in a React App.
What is a memory leak? According to Wikipedia, a memory leak is a type of resource leak... Tagged with react, javascript, webdev, tutorial....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@DominuS-RU could you check if you still see leakage with patch
com.github.masc3d:blurview:17c1cdc48c
it requires
repositories { maven { url 'https://jitpack.io' } }
@masc3d would really appreciate it