1

帮助了解是否存在内存泄漏。
分段

public class NewsFragment extends Fragment {
//some code
private OnNewsFeedsContentClickListener onNewsFeedsContentClickListener = new OnNewsFeedsContentClickListener()
{
    @Override
    public void onClick(String sYoutubeId, ContentType type)
    {
        //some code
    }
}

}
适配器

public class HowToAdapter extends BaseAdapter {

public static final String TAG = "HowToAdapter";
private List<ContentSkill> mContentList = null;
private Context mContext = null;
private ImageLoader mImageLoader = null;
private OnNewsFeedsContentClickListener mOnNewsFeedsContentClickListener = null;

public HowToAdapter(Context context, List<ContentSkill> contetnList, OnNewsFeedsContentClickListener onNewsFeedsContentClickListener)
{
    mContext = context;
    mContentList = contetnList;
    mImageLoader = new ImageLoader(mContext, ImageType.HOW_TO);
    mOnNewsFeedsContentClickListener = onNewsFeedsContentClickListener;
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
    HowToView view = null;
    if (convertView == null)
    {
        view = new HowToView(mContext);
    }
    else
    {
        view = (HowToView) convertView;
    }
    ContentSkill content = getItem(position);
    if (content != null)
    {
        ViewHolder holder = (ViewHolder) view.getTag();
        final String url = Utils.getYouTubeUrlImageFromUrl(content.getUrl());
        final String youtubeId = Utils.getYoutubeIdFromUrl(content.getUrl());
        mImageLoader.displayImage(url, holder.pIvThumb);
        holder.pIvThumb.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                mOnNewsFeedsContentClickListener.onClick(youtubeId, ContentType.VIDEO);
            }
        });
    }
    return view;
}

问题 :
_

  1. 适配器变量final String youtubeId总是会被创建,但不会被杀死?也就是说,每次都会创建 getView() 但旧的youtubeId无法从内存中清除?
  2. 每次调用getView() OnClickListener 也会被创建,老的会被清理出内存?

我认为每次都会重新创建变量并赶上旧内存。

4

0 回答 0