Where should I unbind ButterKnife 8.x.x in a ViewHolder?

I have a RecycleView.ViewHolder class which use ButterKnife annotations.

Should my code unbind() in this ViewHolder class too?

  • Firebase Cloud Messaging not calling FirebaseInstanceId
  • What kind of pitfals exist for the Android APK signing?
  • SwipeRefreshLayout with scrollView and Layout above
  • API to automatically upload apk to Google Play?
  • Android “No content provider found for permission revoke”
  • Emulator for Android 4.4 KitKat is not starting
  • public class AView extends RecyclerView.ViewHolder
        @BindView(R.id.a_text_view) TextView aText;
        public AView(final View view)
            ButterKnife.bind(this, view); // It returns an Unbinder, but where should I call its unbind()?

    The docs (http://jakewharton.github.io/butterknife/) does not talk about this issue.

    Related posts:

    Android In-App Billing failure, saying “You already have a pending order for this item.&am...
    Set drag margin for Android Navigation Drawer
    How to import self-signed SSL certificate to Volley on Android 4.1+
    Error inflating class fragment - duplicate id/illegalargumentexception?
    PreferenceFragment is shown transparently
    Android seekbar solution
  • Android crash reporting library (pre Froyo)
  • How to declare the layout for 7'inch tablet Android?
  • FragmentTabHost - Tabs not addressable until viewed for the first time
  • Difference between code before and after super()
  • Is my Android App Draining Battery?
  • How do Gravity values effect PopupWindow.showAtLocation() in Android
  • 4 Solutions collect form web for “Where should I unbind ButterKnife 8.x.x in a ViewHolder?”

    According to Jake Wharton, author of Butterknife, unbind() is only required for Fragments. See this comment on the issue tracker:


    Q: In the RecyclerView, how do we unbind the ViewHolder?

    A: You don’t need to. Only Fragments need to in onDestroyView().

    The reason being that

    [ViewHolders] don’t outlive the associated view. A Fragment does.

    In other words, because a Fragment may continue to exist after its Views are destroyed, you need to call .unbind() from a Fragment to release the reference to the Views (and allow the associated memory to be reclaimed).

    With a ViewHolder, the lifecycle of the holder is the same as the Views it holds. In other words, the ViewHolder and its Views are destroyed at the same time, so there’s never a lingering reference from one to the other that you need to manually clear.

    Here’s an explanation WHEN and WHY to use unbind() method:


    Fragments have a different view lifecycle than activities. When
    binding a fragment in onCreateView, set the views to null in
    onDestroyView. Butter Knife returns an Unbinder instance when you
    call bind to do this for you. Call its unbind method in the
    appropriate lifecycle callback.

    public class FancyFragment extends Fragment {
      @BindView(R.id.button1) Button button1;
      @BindView(R.id.button2) Button button2;
      private Unbinder unbinder;
      @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fancy_fragment, container, false);
        unbinder = ButterKnife.bind(this, view);
        // TODO Use fields...
        return view;
      @Override public void onDestroyView() {

    From: http://jakewharton.github.io/butterknife/#reset

    so you don’t need at all to unbind any view from ViewHolder.

    Hope it will help

    Yes, they do.
    This is only needed for Fragments.

    There is an example in the doc, which demonstrates how to use this library in the ViewHolder:

    static class ViewHolder {
        @BindView(R.id.title) TextView name;
        @BindView(R.id.job_title) TextView jobTitle;
        public ViewHolder(View view) {
          ButterKnife.bind(this, view);

    So, it’s no need to call unbind for your ViewHolder.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.