/** * Identical to {@link #watch(Object, String)} with an empty string reference name. * * @see #watch(Object, String) */ public void watch(Object watchedReference) { watch(watchedReference, ""); }
@Override public void onFragmentDestroyed(FragmentManager fm, Fragment fragment) { refWatcher.watch(fragment); } };
@Override public void onFragmentDestroyed(FragmentManager fm, Fragment fragment) { refWatcher.watch(fragment); } };
@Override public void onActivityDestroyed(Activity activity) { refWatcher.watch(activity); } };
@Override public void onFragmentViewDestroyed(FragmentManager fm, Fragment fragment) { View view = fragment.getView(); if (view != null) { refWatcher.watch(view); } }
@Override public void onFragmentViewDestroyed(FragmentManager fm, Fragment fragment) { View view = fragment.getView(); if (view != null) { refWatcher.watch(view); } }
@Override public void onDestroy() { super.onDestroy(); RefWatcher refWatcher = MyApp.getRefWatcher(); refWatcher.watch(this); } }
@Override public void onDestroy() { Log.i(TAG, "Conductor: onDestroy() called"); super.onDestroy(); if (hasExited) { DemoApplication.refWatcher.watch(this); } }
@Override public void onDestroy() { super.onDestroy(); if (hasExited) { DemoApplication.refWatcher.watch(this); } }
@Override public void onDestroy() { super.onDestroy(); Log.i(TAG, "onDestroy() called"); if (hasExited) { DemoApplication.refWatcher.watch(this); } }
@Override public void onDestroy() { super.onDestroy(); Log.i(TAG, "onDestroy() called"); if (hasExited) { DemoApplication.refWatcher.watch(this); } }
@Override public void onDestroy() { super.onDestroy(); Log.i(TAG, "onDestroy() called"); if (hasExited) { DemoApplication.refWatcher.watch(this); } }
@Override protected void onChangeEnded(@NonNull ControllerChangeHandler changeHandler, @NonNull ControllerChangeType changeType) { super.onChangeEnded(changeHandler, changeType); hasExited = !changeType.isEnter; if (isDestroyed()) { DemoApplication.refWatcher.watch(this); } }
@Override protected void onChangeEnded(@NonNull ControllerChangeHandler changeHandler, @NonNull ControllerChangeType changeType) { super.onChangeEnded(changeHandler, changeType); hasExited = !changeType.isEnter; if (isDestroyed()) { DemoApplication.refWatcher.watch(this); } }
@Override public void onDestroy() { super.onDestroy(); RefWatcher refWatcher = App.getRefWatcher(getActivity()); if (refWatcher != null) refWatcher.watch(this); }
@Override protected void onChangeEnded(@NonNull ControllerChangeHandler changeHandler, @NonNull ControllerChangeType changeType) { super.onChangeEnded(changeHandler, changeType); hasExited = !changeType.isEnter; if (isDestroyed()) { DemoApplication.refWatcher.watch(this); } } }
@Override protected void onChangeEnded(@NonNull ControllerChangeHandler changeHandler, @NonNull ControllerChangeType changeType) { super.onChangeEnded(changeHandler, changeType); hasExited = !changeType.isEnter; if (isDestroyed()) { DemoApplication.refWatcher.watch(this); } }
@Test public void detectsLeak() { leaking = new Date(); RefWatcher refWatcher = LeakCanary.installedRefWatcher(); refWatcher.watch(leaking); InstrumentationLeakDetector leakDetector = new InstrumentationLeakDetector(); InstrumentationLeakResults results = leakDetector.detectLeaks(); if (results.detectedLeaks.size() != 1) { throw new AssertionError("Expected exactly one leak, not " + results.detectedLeaks.size()); } InstrumentationLeakResults.Result firstResult = results.detectedLeaks.get(0); String leakingClassName = firstResult.analysisResult.className; if (!leakingClassName.equals(Date.class.getName())) { throw new AssertionError("Expected a leak of Date, not " + leakingClassName); } } }
/** * In theory, this test doesn't have a 100% chance of success. In practice, {@link * GcTrigger#DEFAULT} is good enough. */ @Test public void unreachableObject_noDump() { TestDumper dumper = new TestDumper(); TestExecutor executor = new TestExecutor(); RefWatcher refWatcher = defaultWatcher(dumper, executor); refWatcher.watch(new Object()); executor.retryable.run(); assertFalse(dumper.called); }
@Test public void retainedObject_triggersDump() { TestDumper dumper = new TestDumper(); TestExecutor executor = new TestExecutor(); RefWatcher refWatcher = defaultWatcher(dumper, executor); ref = new Object(); refWatcher.watch(ref); executor.retryable.run(); assertTrue(dumper.called); }