Skeleton icon indicating copy to clipboard operation
Skeleton copied to clipboard

Leak canary detects memory leaks when using view based skeleton

Open apexkid opened this issue 4 years ago • 3 comments

skeletonScreen = Skeleton.bind(rootView)
                    .color(R.color.tlShimmerColor)
                    .load(R.layout.item_skeleton_view_profile)
                    .show();

Leads to FrameLayout being leaked. My analysis is that this is due to this function:

private ShimmerLayout generateShimmerContainerLayout(ViewGroup parentView) {
        final ShimmerLayout shimmerLayout = (ShimmerLayout) LayoutInflater.from(mActualView.getContext()).inflate(R.layout.layout_shimmer, parentView, false);
        shimmerLayout.setShimmerColor(mShimmerColor);
        shimmerLayout.setShimmerAngle(mShimmerAngle);
        shimmerLayout.setShimmerAnimationDuration(mShimmerDuration);
        View innerView = LayoutInflater.from(mActualView.getContext()).inflate(mSkeletonResID, shimmerLayout, false);
        ViewGroup.LayoutParams lp = innerView.getLayoutParams();
        if (lp != null) {
            shimmerLayout.setLayoutParams(lp);
        }
        shimmerLayout.addView(innerView);
        shimmerLayout.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
            @Override
            public void onViewAttachedToWindow(View v) {
                shimmerLayout.startShimmerAnimation();
            }

            @Override
            public void onViewDetachedFromWindow(View v) {
                shimmerLayout.stopShimmerAnimation();
            }
        });
        shimmerLayout.startShimmerAnimation();
        return shimmerLayout;
    }

A new object is being inflated which internally uses the rootView but it is never destroyed explicitly.

apexkid avatar Sep 14 '19 18:09 apexkid

setting mViewReplacer to null fixed this issue (did it using reflection as a quick hack).
don't think anyone is managing this project or responding to PRs now.

bhpcode avatar May 21 '20 10:05 bhpcode

where is mViewReplacer, I don't see in the above code

avinashbanswada avatar May 29 '20 18:05 avinashbanswada

setting mViewReplacer to null fixed this issue (did it using reflection as a quick hack). don't think anyone is managing this project or responding to PRs now.

Hi @bhpcode Can you please eloborate how you fixed this, I am facing same issue

avinashbanswada avatar May 30 '20 12:05 avinashbanswada