[BREAKING] Use event class instead of event for timings. Fixes BUKKIT-4664

TimedRegisteredListener uses a reference to the first event fired. This
causes a memory leak in the server for any references that event has. This
changes TimedRegisteredListener to only store a reference to the class of
the event.

This change is intentionally a breaking change, as it is an obscure part
of the API. A non-breaking change would require the leak to be maintained
or an immediate update for any plugins using the method, as it would be an
indirect break.

A unit test is also included to check behavior of shared superclass
functionality.

By: Score_Under <seejay.11@gmail.com>
This commit is contained in:
Bukkit/Spigot
2012-07-05 23:51:12 +01:00
parent 9bc7b6277e
commit d8cfc3fa42
3 changed files with 86 additions and 14 deletions

View File

@@ -84,9 +84,9 @@ public class TimingsCommand extends BukkitCommand {
if (count == 0) continue;
long avg = time / count;
totalTime += time;
Event event = trl.getEvent();
if (count > 0 && event != null) {
fileTimings.println(" " + event.getClass().getSimpleName() + (trl.hasMultiple() ? " (and others)" : "") + " Time: " + time + " Count: " + count + " Avg: " + avg);
Class<? extends Event> eventClass = trl.getEventClass();
if (count > 0 && eventClass != null) {
fileTimings.println(" " + eventClass.getSimpleName() + (trl.hasMultiple() ? " (and sub-classes)" : "") + " Time: " + time + " Count: " + count + " Avg: " + avg);
}
}
}