mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-04 06:28:28 +08:00
Added track and untrack methods to TrackedDisposable's companion object so that disposables that don't extend TrackedDisposable can still take part in tracking and memory leak detection.
This commit is contained in:
parent
b5a6ca6dc3
commit
4c37e8f741
@ -9,22 +9,14 @@ abstract class TrackedDisposable : Disposable {
|
||||
private set
|
||||
|
||||
init {
|
||||
disposableCount++
|
||||
|
||||
if (trackPrecise) {
|
||||
@Suppress("LeakingThis")
|
||||
disposables.add(this)
|
||||
}
|
||||
@Suppress("LeakingThis")
|
||||
track(this)
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
if (!disposed) {
|
||||
disposed = true
|
||||
disposableCount--
|
||||
|
||||
if (trackPrecise) {
|
||||
disposables.remove(this)
|
||||
}
|
||||
untrack(this)
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,6 +45,22 @@ abstract class TrackedDisposable : Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
fun track(disposable: Disposable) {
|
||||
disposableCount++
|
||||
|
||||
if (trackPrecise) {
|
||||
disposables.add(disposable)
|
||||
}
|
||||
}
|
||||
|
||||
fun untrack(disposable: Disposable) {
|
||||
disposableCount--
|
||||
|
||||
if (trackPrecise) {
|
||||
disposables.remove(disposable)
|
||||
}
|
||||
}
|
||||
|
||||
fun checkLeakCountZero(leakCount: Int) {
|
||||
check(leakCount == 0) {
|
||||
buildString {
|
||||
|
Loading…
Reference in New Issue
Block a user