main

square/leakcanary

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

LeakingThread.kt

TLDR

This file contains a LeakingThread class that extends the Thread class. It creates a thread that waits for a notification to proceed. The class also has a companion object that includes a static thread property.

Classes

LeakingThread

The LeakingThread class is a subclass of the Thread class. It represents a thread that waits for a notification to proceed. The class has the following properties and methods:

  • leakedViews: A mutable list of View objects that serves as the container for leaked views.
  • run(): Overrides the run method of the Thread class. It synchronizes on an object and waits until a notification is received.

Companion object

The companion object represents the static part of the LeakingThread class. It contains the following properties:

  • obj: A private static object used for synchronization.
  • thread: A static property that stores an instance of the LeakingThread class.
package com.example.leakcanary

import android.view.View

class LeakingThread : Thread() {

  val leakedViews = mutableListOf<View>()

  init {
    name = "Leaking thread"
    start()
  }

  override fun run() {
    synchronized(obj) {
      obj.wait()
    }
  }

  companion object {
    private val obj = Object()
    val thread = LeakingThread()
  }
}