2016-08-16 45 views
1
below is my leak report captured by leak canary but i am not able to detect from where it keeps referencing object 

    * GC ROOT maps.O.n.d 
    * references maps.ae.e.i 
    * references java.util.ArrayList.array 
    * references array java.lang.Object[].[15] 
    * references maps.af.a$2.b 
    * references maps.af.a.c 
    * references maps.af.b.c 
    * references maps.af.d.mParent 
    * references android.widget.FrameLayout.mParent 
    * references com.google.android.gms.maps.MapView.mParent 
    * references android.widget.LinearLayout.mParent 
    * references android.support.v7.widget.CardView.mParent 
    * references android.widget.LinearLayout.mLayoutParams 
    * references android.support.v7.widget.RecyclerView$LayoutParams.mViewHolder 
    * references com.aimdek.healthwel.adapter.FeedsAdpter$MyViewHolder.this$0 
    * references com.aimdek.healthwel.adapter.FeedsAdpter.feedsFragment 
    * leaks com.aimdek.healthwel.fragment.FeedsFragment instance 

    * Retaining: 1.0 KB. 
    * Reference Key: f46244a8-7376-452a-969b-6f19fd070ea2 
    * Device: motorola motorola XT1068 titan_retaildsds 
    * Android Version: 6.0 API: 23 LeakCanary: 1.4-beta2 3799172 
    * Durations: watch=5202ms, gc=259ms, heap dump=13581ms, analysis=108725ms 

    * Details: 
    * Instance of maps.O.n 
    | static f = [email protected] (0x12cd0610) 
    | static $staticOverhead = byte[8]@328672257 (0x13972401) 
    | g = -1 
    | f = false 
    | g = 256 
    | h = [email protected] (0x12cd0610) 
    | i = 0 
    | j = 1 
    | k = 2.0 
    | b = [email protected] (0x13353b20) 
    | c = [email protected] (0x12dbde60) 
    | d = [email protected] (0x13cd0380) 
    | f = null 
    | g = [email protected] (0x12cd08f0) 
    | h = [email protected] (0x138e2660) 
    | i = [email protected] (0x12dec100) 
    | j = false 
    | k = [email protected] (0x12cf3ac0) 
    | l = [email protected] (0x12dc6d80) 
    | m = [email protected] (0x12dc6de0) 
    | n = [email protected] (0x13353af0) 
    | o = 3000 
    | p = 0 
    | q = 0 
    | r = 0 
    | s = false 
    | t = [email protected] (0x12dc6dc0) 
    | u = false 
    | v = [email protected] (0x12cd0900) 
    | contextClassLoader = [email protected] (0x12c88c60) 
    | daemon = false 
    | group = java.lang.Thread[email protected] (0x6f71a5c8) 
    | hasBeenStarted = true 
    | id = 9069 
    | inheritableValues = null 
    | interruptActions = [email protected] (0x12dc6c80) 
    | localValues = [email protected] (0x12dec0a0) 
    | lock = [email protected] (0x12cd08e0) 
    | name = [email protected] (0x13353a60) 
    | nativePeer = -1194656976 
    | parkBlocker = null 
    | parkState = 1 
    | priority = 5 
    | stackSize = 0 
    | target = null 
    | uncaughtHandler = null 
    | shadow$_klass_ = maps.O.n 
    | shadow$_monitor_ = 1267345999 
    * Instance of maps.ae.e 
    | static $staticOverhead = byte[24]@331324817 (0x13bf9d91) 
    | static j = [email protected] (0x13cc3b60) 
    | static s = [email protected] (0x13ccf2b0) 
    | static a = 
    | mParentFragment = [email protected] (0x12e7b180) 
    | mReenterTransition = [email protected] (0x13753160) 
    | mRemoving = false 
    | mRestored = false 
    | mRetainInstance = false 
    | mRetaining = false 
    | mReturnTransition = [email protected] (0x13753160) 
    | mSavedFragmentState = null 
    | mSavedViewState = [email protected] (0x135a1de0) 
    | mSharedElementEnterTransition = null 
    | mSharedElementReturnTransition = [email protected] (0x13753160) 
    | mState = 0 
    | mStateAfterAnimating = 0 
    | mTag = null 
    | mTarget = null 
    | mTargetIndex = -1 
    | mTargetRequestCode = 0 
    | mUserVisibleHint = false 
    | mView = null 
    | mWho = null 
    | shadow$_klass_ = com.aimdek.healthwel.fragment.FeedsFragment 
    | shadow$_monitor_ = -2095684492 
    * Excluded Refs: 
    | Field: android.view.inputmethod.InputMethodManager.mNextServedView 
    | Field: android.view.inputmethod.InputMethodManager.mServedView 
    | Field: android.view.inputmethod.InputMethodManager.mServedInputConnection 
    | Field: android.view.inputmethod.InputMethodManager.mCurRootView 
    | Field: android.widget.Editor$Blink.this$0 
    | Field: android.view.Choreographer$FrameDisplayEventReceiver.mMessageQueue (always) 
Instance of com.aimdek.healthwel.adapter.FeedsAdpter 
| allFeedsList = [email protected] (0x137a6820) 
| context = [email protected] (0x12c69700) 
| feedsFragment = [email protected] (0x12cc8f00) 
| inflater = [email protected] (0x133bd160) 
| mHasStableIds = false 
| mObservable = [email protected]485552 (0x12dd2fb0) 
| shadow$_klass_ = com.aimdek.healthwel.adapter.FeedsAdpter 
| shadow$_monitor_ = 0 
* Instance of com.aimdek.healthwel.fragment.FeedsFragment 
| adapter = [email protected] (0x1322a920) 
| birthday = [email protected] (0x13d64c00) 
| dateformat = [email protected] (0x13219a80) 
| email = [email protected] (0x13cefc00) 
| feedsId = null 
| friendImg = [email protected] (0x13d63800) 
| friendInfo = null 
| imgBackground = [email protected] (0x13cadc00) 
| imgFriendBackground = [email protected] (0x13a0bc00) 
| page = 1 
| profile = [email protected] (0x13cad000) 
| recyclerView = [email protected] (0x13d65400) 
| secondLevel = false 
| tvBirthDate = [email protected] (0x13d65000) 
| tvEmailId = [email protected] (0x13cf0800) 
| tvHeight = [email protected] (0x13d64800) 
| tvName = [email protected] (0x13d63c00) 
| tvWeight = [email protected] (0x13cee800) 
| type = 21 
| userId = [email protected] (0x12c06ec0) 
| activity = [email protected]04672 (0x12c69700) 
| mAdded = false 
| mAllowEnterTransitionOverlap = null 
| mAllowReturnTransitionOverlap = null 
| mAnimatingAway = null 
| mArguments = [email protected] (0x13219ae0) 
| mBackStackNesting = 0 
| mCalled = true 
| mCheckedForLoaderManager = false 
| mChildFragmentManager = null 
| mContainer = null 
| mContainerId = 0 
| mDeferStart = false 
| mDetached = false 
| mEnterTransition = null 
| mEnterTransitionCallback = null 
| mExitTransition = null 
| mExitTransitionCallback = null 
| mFragmentId = 0 
| mFragmentManager = null 
| mFromLayout = false 
| mHasMenu = true 
| mHidden = false 
| mHost = null 
| mInLayout = false 
| mIndex = -1 
| mInnerView = null 
| mLoaderManager = null 
| mLoadersStarted = false 
| mMenuVisible = false 
| mNextAnim = 0 
| mParentFragment = [email protected] (0x12e7b180) 
| mReenterTransition = [email protected] (0x13753160) 
| mRemoving = false 
| mRestored = false 
| mRetainInstance = false 
| mRetaining = false 
| mReturnTransition = [email protected] (0x13753160) 
| mSavedFragmentState = null 
| mSavedViewState = [email protected] (0x135a1de0) 
| mSharedElementEnterTransition = null 
| mSharedElementReturnTransition = [email protected] (0x13753160) 
| mState = 0 
| mStateAfterAnimating = 0 
| mTag = null 
| mTarget = null 
| mTargetIndex = -1 
| mTargetRequestCode = 0 
| mUserVisibleHint = false 
| mView = null 
| mWho = null 
| shadow$_klass_ = com.aimdek.healthwel.fragment.FeedsFragment 
| shadow$_monitor_ = -2095684492 
下面

检测从泄漏报告基准为FeedsAdapter无法通过Leakcanary

public class FeedsAdpter extends RecyclerView.Adapter<FeedsAdpter.MyViewHolder> { 
    private LayoutInflater inflater; 
    private Context context; 
    private FeedsFragment feedsFragment; 
    private ArrayList<FeedsDto> allFeedsList = new ArrayList<FeedsDto>(); 


    public FeedsAdpter(Context context, FeedsFragment feedsFragment) { 
     this.context = context; 
     this.feedsFragment = feedsFragment; 
     inflater = LayoutInflater.from(context); 
    } 

    @Override 
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     View view = inflater.inflate(R.layout.item_feeds, parent, false); 
     MyViewHolder holder = new MyViewHolder(view); 
     return holder; 
    } 

    @Override 
    public void onViewRecycled(MyViewHolder holder) { 
     super.onViewRecycled(holder); 
     if(Validator.isNotNull(holder.mapView.getMap())) { 
      GoogleMap googleMap = holder.mapView.getMap(); 
      googleMap.clear(); 
      googleMap.setMapType(GoogleMap.MAP_TYPE_NONE); 
      googleMap=null; 
     } 
    } 

    @Override 
    public void onBindViewHolder(final MyViewHolder holder, int position) { 
     final FeedsDto feeds = allFeedsList.get(position); 
     GoogleMap googleMap; 
     if (Validator.isNotNull(feeds)) { 
      if (Validator.isNotNull(feeds.getImagePreviewUrl())) { 
       //imageLoader.displayImage(feeds.getImagePreviewUrl(), holder.userImg, HWUtil.IMAGE_OPTIONS); 
       Picasso.with(context).setIndicatorsEnabled(true); 
       Picasso.with(context) 
         .load(feeds.getImagePreviewUrl()) 
         .resize(50,50) 
         .onlyScaleDown() 
         .placeholder(R.drawable.ic_launcher) 
         .error(R.drawable.profile_small_img) 
         .into(holder.userImg); 
      } else { 
       holder.userImg.setImageResource(R.drawable.profile_small_img); 
      } 
      holder.tvUserName.setText(feeds.getFullName()); 
      MainActivity activity = (MainActivity) context; 
      String tempMsg = feeds.getFeeds().getMessage(); 

      if (Validator.isNotNull(feeds.getFeeds().getHistoryId())) { 
       if (feeds.getFeeds().getUserId().equals(activity.preferences.getUserInfo().getId())) { 
        tempMsg = tempMsg.replace("[$ACTIVITY_OWNER$]", activity.getResources().getString(R.string.was_out)); 
       } else { 
        tempMsg = tempMsg.replace("[$ACTIVITY_OWNER$]", activity.getResources().getString(R.string.was_out)); 
       } 
      } else { 
       tempMsg = tempMsg.replace("[$ACTIVITY_OWNER$]", ""); 
      } 

      holder.tvMsg.setText(tempMsg); 
      if (feeds.isLiked()) { 
       holder.likeBtn.setImageResource(R.drawable.like_icon_pink); 
      } else { 
       holder.likeBtn.setImageResource(R.drawable.like_icon_grey); 
      } 
      holder.tvDuration.setText(feeds.getFeedCreatedTime()); 
      if (Validator.isNotNull(feeds.getFeeds().getHistoryMap()) && feeds.getFeeds().getHistoryMap().length > 0) { 
       if (holder.mapView != null) { 
        holder.mapView.onCreate(null); 
        holder.mapView.setVisibility(View.VISIBLE); 
        holder.mapView.getMapAsync(new OnMapReadyCallback() { 
         @Override 
         public void onMapReady(GoogleMap googleMap) { 
          if (Validator.isNotNull(googleMap)) { 
           googleMap.clear(); 
           holder.mapView.setClickable(false); 
           googleMap.getUiSettings().setMapToolbarEnabled(false); 
           List<HistoryMap> historyMaps = new ArrayList<HistoryMap>(); 
           historyMaps.addAll(Arrays.asList(feeds.getFeeds().getHistoryMap())); 
           HWUtil.drawRouteIntoMap(historyMaps, googleMap); 
          } 
         } 
        }); 

       } 
      } else { 
       holder.mapView.setVisibility(View.GONE); 
      } 

      holder.tvCommentcount.setText(String.valueOf(feeds.getFeeds().getCommentCount())); 
      if (feeds.getFeeds().getCommentCount() == 0) { 
       holder.commentBtn.setImageResource(R.drawable.comment_icon_grey_feeds); 
      } else { 
       holder.commentBtn.setImageResource(R.drawable.comment_icon_feeds); 
      } 
      holder.tvLikecount.setText(String.valueOf(feeds.getFeeds().getLikeCount())); 

      holder.tvPost.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        if (Validator.isNotNull(holder.etComment.getText().toString())) { 
         hideKeyboard(context); 
         String comment = holder.etComment.getText().toString(); 
         feedsFragment.updateComment(feeds.getFeeds().getId(), comment); 
         holder.etComment.setText(HWUtil.BLANK); 
        } else { 
         HWUtil.showToast(context, context.getResources().getString(R.string.enter_comment)); 
        } 
       } 
      }); 
      holder.likeBtn.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        feedsFragment.updateComment(feeds.getFeeds().getId(), null); 
       } 
      }); 
      holder.commentBtn.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        MainActivity activity = (MainActivity) context; 
        activity.setTitle(context.getString(R.string.comment)); 
        activity.preferences.setBack(true); 
        activity.preferences.setFeedsDto(feeds); 
        activity.replaceFragment(new CommentFragment(), null); 
       } 
      }); 
     } 
    } 


    public static void hideKeyboard(Context context) { 

     try { 
      InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); 

      View view = ((Activity) context).getCurrentFocus(); 
      if (view != null) { 
       inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 
      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    public void addAll(List<FeedsDto> list) { 
     allFeedsList.addAll(list); 
     notifyDataSetChanged(); 
    } 

    public void clear() { 
     allFeedsList = new ArrayList<FeedsDto>(); 
     notifyDataSetChanged(); 
    } 


    @Override 
    public int getItemCount() { 
     return allFeedsList.size(); 
    } 

    public void updateFeeds(String feedsId, com.aimdek.healthwel.dto.Response response, int type) { 
     FeedsDto dto = getFeedsDto(feedsId); 
     if (Validator.isNotNull(dto)) { 
      if (type == Request.LIKE_UNLIKE) { 
       dto.getFeeds().setLikeCount(response.getCount()); 
       dto.setLiked(response.isLiked()); 
      } else { 
       dto.getFeeds().setCommentCount(response.getCount()); 
      } 
     } 
     notifyDataSetChanged(); 
    } 


    public FeedsDto getFeedsDto(String feedsId) { 
     for (FeedsDto dto : allFeedsList) { 
      if (dto.getFeeds().getId().equals(feedsId)) { 
       return dto; 
      } 
     } 
     return null; 
    } 

    public class MyViewHolder extends RecyclerView.ViewHolder { 
     @Bind(R.id.img_user_pic) 
     ImageView userImg; 
     @Bind(R.id.tv_user_name) 
     TextView tvUserName; 
     @Bind(R.id.tv_duration) 
     TextView tvDuration; 
     @Bind(R.id.tv_msg) 
     TextView tvMsg; 
     @Bind(R.id.workout_map_summary) 
     MapView mapView; 
     @Bind(R.id.et_feeds_comment) 
     EditText etComment; 
     @Bind(R.id.tv_post) 
     TextView tvPost; 
     @Bind(R.id.img_like_btn) 
     ImageButton likeBtn; 
     @Bind(R.id.img_comment_btn) 
     ImageButton commentBtn; 
     @Bind(R.id.tv_like_count) 
     TextView tvLikecount; 
     @Bind(R.id.tv_comment_count) 
     TextView tvCommentcount; 


     public MyViewHolder(View view) { 
      super(view); 
      ButterKnife.bind(this, view); 
     } 
    } 
} 

作为用户喜欢或上的特定评论进给I调用片段类方法来更新这和IM表示朋友的饲料代码app.which会创建泄漏时,显示个人朋友的饲料任何想法如何解决这个问题。任何帮助是appriciated

回答

2

你应该释放mNextServedView当关注的窗口被解雇(如onStop或onDestory)。

这样的代码:

InputMethodManager methodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); 
    try { 
     Field mNextServedView = methodManager.getClass().getDeclaredField("mNextServedView"); 
     mNextServedView.setAccessible(true); 
     mNextServedView.set(methodManager, null); 

     Field mServedView = methodManager.getClass().getDeclaredField("mServedView"); 
     mServedView.setAccessible(true); 
     mServedView.set(methodManager, null); 

     Method method = methodManager.getClass().getDeclaredMethod("finishInputLocked"); 
     method.setAccessible(true); 
     method.invoke(methodManager); 
    } catch (Throwable e) { 
     e.printStackTrace(); 
    } 
+0

@ muyiou但我是用在Adpater类 –

+0

@Hardik梅塔所以你应该添加回调Adpater输入法管理器 – muyiou