Skip to content

Commit 67f0001

Browse files
committed
Solve Memory Leak: Explicit ownership of one set per tick listeners
1 parent 873a84f commit 67f0001

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

src/main/kotlin/com/lambda/util/OneSetPerTick.kt

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ class OneSetPerTick<T>(
3535
private set
3636

3737
init {
38-
instances.add(this)
38+
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {
39+
setThisTick = false
40+
if (resetAfterTick) reset()
41+
}
3942
}
4043

4144
@Suppress("Unused")
@@ -60,22 +63,4 @@ class OneSetPerTick<T>(
6063
private fun reset() {
6164
value = defaultValue
6265
}
63-
64-
fun destroy() {
65-
destroyed = true
66-
instances.remove(this)
67-
}
68-
69-
companion object {
70-
private val instances = linkedSetOf<OneSetPerTick<*>>()
71-
72-
init {
73-
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {
74-
instances.forEach {
75-
it.setThisTick = false
76-
if (it.resetAfterTick) it.reset()
77-
}
78-
}
79-
}
80-
}
8166
}

0 commit comments

Comments
 (0)