main

square/leakcanary

Last updated at: 29/12/2023 09:38

LeakAssertions.kt

TLDR

This file contains a single object named LeakAssertions in the leakcanary package. It provides a method assertNoLeaks for asserting that there are no leaks in the heap at a specific point in time.

Methods

assertNoLeaks

Asserts that there are no leaks in the heap at the current point in time. This method should be called on the instrumentation thread and may block the current thread for a significant amount of time. If any leaks are found, this method throws an exception, which will fail the test. The specific details of the assertion depend on the configuration set in DetectLeaksAssert.update. The tag parameter can be used to identify the calling code for reporting purposes or to skip leak detection for specific tags in a subset of tests.

package leakcanary

object LeakAssertions {

  /**
   * Asserts that there are no leak in the heap at this point in time.
   *
   * This method should be called on the instrumentation thread.
   *
   * This method is may block the current thread for a significant amount of time,
   * as it might need to dump the heap and analyze it.
   *
   * If leaks are found, this method is expected to throw an exception, which will fail the test.
   *
   * The specific details depend on what you configured in [DetectLeaksAssert.update].
   *
   * [tag] identifies the calling code, which can then be used for reporting purposes or to skip
   * leak detection for specific tags in a subset of tests (see [SkipLeakDetection]).
   */
  fun assertNoLeaks(tag: String = NO_TAG) {
    DetectLeaksAssert.delegate.assertNoLeaks(tag)
  }

  const val NO_TAG = ""
}