Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leak canary detects memory leaks when using view based skeleton #35

Open
apexkid opened this issue Sep 14, 2019 · 3 comments
Open

Leak canary detects memory leaks when using view based skeleton #35

apexkid opened this issue Sep 14, 2019 · 3 comments

Comments

@apexkid
Copy link

apexkid commented Sep 14, 2019

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.

@bhpcode
Copy link

bhpcode commented May 21, 2020

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.

@avinashbanswada
Copy link

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

@avinashbanswada
Copy link

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

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

No branches or pull requests

3 participants