question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory leaks in BlockingBlurController

See original GitHub issue

Hello, @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:closed
  • Created 5 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
masc3dcommented, May 21, 2019

@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' } }

0reactions
Dimeziscommented, Oct 8, 2019

@masc3d would really appreciate it

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found