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

list场景下有内存泄露,会一直new SkinView,导致多次滑动之后占用的内存会一直增加 #19

Open
flyxl opened this issue Apr 16, 2016 · 2 comments

Comments

@flyxl
Copy link

flyxl commented Apr 16, 2016

public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(MainActivity.this).inflate(R.layout.item, parent, false);
}
SkinManager.getInstance().injectSkin(convertView);
TextView tv = (TextView) convertView.findViewById(R.id.id_tv_title);
tv.setText(getItem(position));
return convertView;
}

public static SkinView getSkinView(View view) {
Object tag = view.getTag(R.id.skin_tag_id);
if (tag == null)
{
tag = view.getTag();
}
if (tag == null) return null;
if (!(tag instanceof String)) return null;
String tagStr = (String) tag;

    List<SkinAttr> skinAttrs = parseTag(tagStr);
    if (!skinAttrs.isEmpty())
    {
        changeViewTag(view);
        **return new SkinView(view, skinAttrs);**
    }
    return null;
}

SkinManager.getInstance().injectSkin每次都会new一个SkinView出来,SkinView的总数量等于getView被调用的总次数,而不是getItemCount的值

@flyxl
Copy link
Author

flyxl commented Oct 25, 2016

从原理上来说,listview里面不可见的item有可能并不在activity的view hierarchy里面,所以哪怕从view hierarchy进行遍历,也有一些item view没有换肤。你可以试一下看看

Xiaolong Wu

On 20 Oct 2016, at 14:54, Rrtoyewx [email protected] wrote:

你可以一上来使用,

SkinManager.getInstance().register(this);
由里面的SkinAttrSupport的每次getSkinViews遍历当前activity中所有的view。
而不是使用

SkinManager.getInstance().injectSkin(convertView);
那是自己设置,所以个数会是getview的次数,


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #19 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AEY4bRSPeo3eEplQIYY_ztJveUlV3ju-ks5q1xAkgaJpZM4II0nl.

@flyxl
Copy link
Author

flyxl commented Oct 25, 2016

从原理上来说,listview里面不可见的item有可能并不在activity的view hierarchy里面,所以哪怕从view hierarchy进行遍历,也有一些item view没有换肤。你可以试一下看看

Xiaolong Wu

On 20 Oct 2016, at 14:54, Rrtoyewx <[email protected] mailto:[email protected]> wrote:

你可以一上来使用,

SkinManager.getInstance().register(this);
由里面的SkinAttrSupport的每次getSkinViews遍历当前activity中所有的view。
而不是使用

SkinManager.getInstance().injectSkin(convertView);
那是自己设置,所以个数会是getview的次数,


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #19 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AEY4bRSPeo3eEplQIYY_ztJveUlV3ju-ks5q1xAkgaJpZM4II0nl.

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

1 participant