AndroidViewHover icon indicating copy to clipboard operation
AndroidViewHover copied to clipboard

Memory leak with mBlurImage

Open techtunde opened this issue 10 years ago • 1 comments

When enableBlurBackground() is set to true, if you monitor the memory of the application, you can see that memory goes up each time you do hover.show(), but doesn't go down when you do hover.hide(). If you look at the code for onAnimationEnd() for mGlobalDisappearAnimators, you see that the image within mBlurImage is not freed. I believe this is what causes the memory leak.

techtunde avatar Sep 04 '15 05:09 techtunde

/** * 使用弱引用 */ private InvalidationLoop invalidationLoop = new InvalidationLoop(this);

private static class InvalidationLoop implements Choreographer.FrameCallback{
    private WeakReference<BlurLayout> blurLayoutWeakReference;

    public InvalidationLoop(BlurLayout blurLayout) {
        this.blurLayoutWeakReference = new WeakReference<>(blurLayout);
    }

    @Override
    public void doFrame(long frameTimeNanos) {
        try {
            if (blurLayoutWeakReference != null && blurLayoutWeakReference.get() != null) {
                BlurLayout blurLayout = blurLayoutWeakReference.get();
                blurLayout.invalidate();
                Choreographer.getInstance().postFrameCallbackDelayed(this, 1000 / mFPS);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

9c-x avatar Nov 11 '20 03:11 9c-x