Skip to content

Commit 3aac87f

Browse files
authored
Account for child EventBuses in dispose() and trim() (#83)
1 parent f6a6e9b commit 3aac87f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/main/java/net/minecraftforge/eventbus/internal/AbstractEventBusImpl.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ default void startup() {
141141
// Force invalidate the invoker to remove the no-op invoker that might've been set by shutdown()
142142
alreadyInvalidated().set(false);
143143
invalidateInvoker();
144+
145+
children().forEach(AbstractEventBusImpl::startup);
144146
}
145-
children().forEach(AbstractEventBusImpl::startup);
146147
}
147148

148149
default void shutdown() {
@@ -154,8 +155,9 @@ default void shutdown() {
154155
// on calls to addListener() to keep the no-op invoker
155156
setNoOpInvoker();
156157
alreadyInvalidated().set(true);
158+
159+
children().forEach(AbstractEventBusImpl::shutdown);
157160
}
158-
children().forEach(AbstractEventBusImpl::shutdown);
159161
}
160162

161163
default void dispose() {
@@ -166,14 +168,22 @@ default void dispose() {
166168

167169
backingList().trimToSize();
168170
monitorBackingList().trimToSize();
171+
172+
children().forEach(AbstractEventBusImpl::dispose);
173+
174+
if (children() instanceof ArrayList<?> childrenArrayList) {
175+
childrenArrayList.clear();
176+
childrenArrayList.trimToSize();
177+
}
169178
}
170-
children().forEach(AbstractEventBusImpl::dispose);
171179
}
172180

173181
default void trim() {
174182
synchronized (backingList()) {
175183
backingList().trimToSize();
176184
monitorBackingList().trimToSize();
185+
if (children() instanceof ArrayList<?> childrenArrayList)
186+
childrenArrayList.trimToSize();
177187
}
178188
}
179189

0 commit comments

Comments
 (0)