com.squareup.leakcanary.RefWatcher Java Examples

The following examples show how to use com.squareup.leakcanary.RefWatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LyricsViewFragment.java    From QuickLyric with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDestroy() {
    unregisterUpdateBroadcastReceiver();
    threadCancelled = true;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && networkCallback != null)
        try {
            ((ConnectivityManager) getActivity().getApplicationContext()
                    .getSystemService(Context.CONNECTIVITY_SERVICE)).unregisterNetworkCallback(networkCallback);
        } catch (IllegalArgumentException ignored) {
        }
    if (Build.VERSION.SDK_INT >= 21 && sessionListener != null) {
        ((MediaSessionManager) getActivity().getSystemService(Context.MEDIA_SESSION_SERVICE))
                .removeOnActiveSessionsChangedListener((OnActiveSessionsChangedListener) sessionListener);
    }
    super.onDestroy();
    RefWatcher refWatcher = App.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
 
Example #2
Source File: GlobalConfiguration.java    From Hands-Chopping with Apache License 2.0 6 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    //当所有模块集成到宿主 App 时, 在 App 中已经执行了以下代码, 所以不需要再执行
    if (BuildConfig.IS_BUILD_MODULE) {
        lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
            @Override
            public void onFragmentDestroyed(FragmentManager fm, android.support.v4.app.Fragment f) {
                ((RefWatcher) ArmsUtils
                        .obtainAppComponentFromContext(f.getActivity())
                        .extras()
                        .get(RefWatcher.class.getName()))
                        .watch(f);
            }
        });
    }
}
 
Example #3
Source File: SampleApplication.java    From RIBs with Apache License 2.0 6 votes vote down vote up
/**
 * Install leak canary for both activities and RIBs.
 */
private void installLeakCanary() {
  final RefWatcher refWatcher = LeakCanary
          .refWatcher(this)
          .watchDelay(2, TimeUnit.SECONDS)
          .buildAndInstall();
  LeakCanary.install(this);
  RibRefWatcher.getInstance().setReferenceWatcher(new RibRefWatcher.ReferenceWatcher() {
    @Override
    public void watch(Object object) {
      refWatcher.watch(object);
    }

    @Override
    public void logBreadcrumb(String eventType, String data, String parent) {
      // Ignore for now. Useful for collecting production analytics.
    }
  });
  RibRefWatcher.getInstance().enableLeakCanary();
}
 
Example #4
Source File: ManageDevicesRecyclerFragment.java    From science-journal with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
  stopScanning();
  mainMenu = null;
  myDevices.onDestroy();
  myDevices = null;
  super.onDestroy();

  // Make sure we don't leak this fragment.
  RefWatcher watcher = WhistlePunkApplication.getAppServices(getActivity()).getRefWatcher();
  watcher.watch(this);
}
 
Example #5
Source File: ActivityBaseInternal.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
void onDestroy() {
    mCheckout = null;
    if (mInputMethodResetRequest) performInputMethodServiceReset();
    // Watch for the activity to detect possible leaks.
    RefWatcher refWatcher = AppHeap.getRefWatcher();
    refWatcher.watch(this);
}
 
Example #6
Source File: BaseFragment.java    From MarkdownEditors with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    if (BuildConfig.DEBUG) {//Debug的时候检查内存泄露
        RefWatcher refWatcher = BaseApplication.getRefWatcher(mContext);
        if (refWatcher != null) {
            refWatcher.watch(this);
        }
    }
}
 
Example #7
Source File: BaseApplication.java    From MarkdownEditors with Apache License 2.0 5 votes vote down vote up
public static RefWatcher getRefWatcher(Context context) {
    if (context == null) {
        return null;
    }
    BaseApplication application = (BaseApplication) context.getApplicationContext();
    if (application.hasMemoryLeak()) {
        return application.refWatcher;
    }
    return null;
}
 
Example #8
Source File: BaseFragment.java    From Loop with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();

    RefWatcher refWatcher = LoopApplication.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
 
Example #9
Source File: SearchFragment.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroy() {
    ((SearchPagerAdapter) ((SearchActivity) getActivity()).getViewPager().getAdapter()).removeFragment(this);
    super.onDestroy();
    RefWatcher refWatcher = App.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
 
Example #10
Source File: PagerFragment.java    From AndroidViewModel with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();

    // watch for memory leaks
    RefWatcher refWatcher = SampleApplication.getRefWatcher(requireActivity());
    refWatcher.watch(this);
}
 
Example #11
Source File: GlobalConfiguration.java    From Hands-Chopping with Apache License 2.0 5 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
        @Override
        public void onFragmentDestroyed(FragmentManager fm, Fragment f) {
            ((RefWatcher) ArmsUtils
                    .obtainAppComponentFromContext(f.getActivity())
                    .extras()
                    .get(RefWatcher.class.getName()))
                    .watch(f);
        }
    });
}
 
Example #12
Source File: GlobalConfiguration.java    From lifecycle-component with Apache License 2.0 5 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
        @Override
        public void onFragmentDestroyed(FragmentManager fm, Fragment f) {
            ((RefWatcher) ArmsUtils
                    .obtainAppComponentFromContext(f.getActivity())
                    .extras()
                    .get(RefWatcher.class.getName()))
                    .watch(f);
        }
    });
}
 
Example #13
Source File: RecentTracksFragment.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroy() {
    RefWatcher refWatcher = App.getRefWatcher(getActivity());
    refWatcher.watch(this);
    EventBus.getDefault().unregister(this);
    super.onDestroy();

}
 
Example #14
Source File: TriggersFragment.java    From hawkular-android-client with Apache License 2.0 4 votes vote down vote up
private void detectLeaks() {
    RefWatcher refWatcher = HawkularApplication.getRefWatcher(getActivity());
    refWatcher.watch(this);
}
 
Example #15
Source File: TrivialApplication.java    From OPFIab with Apache License 2.0 4 votes vote down vote up
public static RefWatcher getRefWatcher(final Context context) {
    final Context applicationContext = context.getApplicationContext();
    final TrivialApplication application = (TrivialApplication) applicationContext;
    return application.refWatcher;
}
 
Example #16
Source File: AppModule.java    From photosearcher with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
protected RefWatcher refWatcher() {
    return RefWatcher.DISABLED;
}
 
Example #17
Source File: SampleApplication.java    From mosby with Apache License 2.0 4 votes vote down vote up
public static RefWatcher getRefWatcher(Context context) {
  SampleApplication application = (SampleApplication) context.getApplicationContext();
  return application.refWatcher;
}
 
Example #18
Source File: SampleApplication.java    From mosby with Apache License 2.0 4 votes vote down vote up
public static RefWatcher getRefWatcher(Context context) {
  SampleApplication application = (SampleApplication) context.getApplicationContext();
  return application.refWatcher;
}
 
Example #19
Source File: DebugAppModule.java    From photosearcher with Apache License 2.0 4 votes vote down vote up
@Override
protected RefWatcher refWatcher() {
    return LeakCanary.install(mApp);
}
 
Example #20
Source File: MailApplication.java    From mosby with Apache License 2.0 4 votes vote down vote up
public static RefWatcher getRefWatcher(Context context) {
  MailApplication application = (MailApplication) context.getApplicationContext();
  return application.refWatcher;
}
 
Example #21
Source File: JDApplication.java    From JianDan_OkHttpWithVolley with Apache License 2.0 4 votes vote down vote up
public static RefWatcher getRefWatcher(Context context) {
    JDApplication application = (JDApplication) context.getApplicationContext();
    return application.refWatcher;
}
 
Example #22
Source File: UtilModule.java    From kaif-android with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
RefWatcher provideRefWatcher() {
  return LeakCanary.install(application);
}
 
Example #23
Source File: Application.java    From materialistic with Apache License 2.0 4 votes vote down vote up
public static RefWatcher getRefWatcher(Context context) {
    Application application = (Application) context.getApplicationContext();
    return application.mRefWatcher;
}
 
Example #24
Source File: App.java    From AlbumSelector with Apache License 2.0 4 votes vote down vote up
public RefWatcher getRrefWatcher() {
    return mRrefWatcher;
}
 
Example #25
Source File: ReaderApplication.java    From BookReader with Apache License 2.0 4 votes vote down vote up
public static RefWatcher getRefWatcher(Context context) {
    ReaderApplication application = (ReaderApplication) context.getApplicationContext();
    return application.refWatcher;
}
 
Example #26
Source File: Apps.java    From zone-sdk with MIT License 4 votes vote down vote up
public static RefWatcher getRefWatcher(Context context) {
    Apps application = (Apps) context.getApplicationContext();
    return application.refWatcher;
}
 
Example #27
Source File: SampleApplication.java    From LocalMessageManager with Apache License 2.0 4 votes vote down vote up
public static RefWatcher getRefWatcher(Context context) {
    SampleApplication application = (SampleApplication) context.getApplicationContext();
    return application.refWatcher;
}
 
Example #28
Source File: App.java    From gank with GNU General Public License v3.0 4 votes vote down vote up
public static RefWatcher getRefWatcher(Context context) {
    App application = (App) context.getApplicationContext();
    return application.refWatcher;
}
 
Example #29
Source File: LeakTool.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
private RefWatcher getRefWatcher() {
  if (refWatcher == null) {
    throw new IllegalStateException("Call setup first!");
  }
  return refWatcher;
}
 
Example #30
Source File: SampleApplication.java    From SimpleRecyclerAdapter with Apache License 2.0 4 votes vote down vote up
public static RefWatcher getRefWatcher(Context context) {
    SampleApplication application = (SampleApplication) context.getApplicationContext();
    return application.refWatcher;
}