Fix a memory leak.

This commit is contained in:
Olof Larsson 2015-05-11 10:11:13 +02:00
parent 9c49986774
commit b286c81cb3

View File

@ -334,13 +334,26 @@ public class MassiveCoreEngineMain extends EngineAbstract
protected Map<String, Map<SenderColl<?>, Entry<JsonElement, Long>>> idToRemoteEntries = new ConcurrentHashMap<String, Map<SenderColl<?>, Entry<JsonElement, Long>>>(); protected Map<String, Map<SenderColl<?>, Entry<JsonElement, Long>>> idToRemoteEntries = new ConcurrentHashMap<String, Map<SenderColl<?>, Entry<JsonElement, Long>>>();
// Intended to be ran asynchronously. // Intended to be ran asynchronously.
public void storeRemoteEntries(String playerId) public void storeRemoteEntries(final String playerId)
{ {
// Create remote entries ... // Create remote entries ...
Map<SenderColl<?>, Entry<JsonElement, Long>> remoteEntries = createRemoteEntries(playerId); Map<SenderColl<?>, Entry<JsonElement, Long>> remoteEntries = createRemoteEntries(playerId);
// ... and store them. // ... store them ...
this.idToRemoteEntries.put(playerId, remoteEntries); this.idToRemoteEntries.put(playerId, remoteEntries);
// ... and make sure they are removed after 30 seconds.
// Without this we might cause a memory leak.
// Players might trigger AsyncPlayerPreLoginEvent but not PlayerLoginEvent.
// Using WeakHashMap is not an option since the player object does not exist at AsyncPlayerPreLoginEvent.
Bukkit.getScheduler().runTaskLaterAsynchronously(this.getPlugin(), new Runnable()
{
@Override
public void run()
{
idToRemoteEntries.remove(playerId);
}
}, 20*30);
} }
// Intended to be ran synchronously. // Intended to be ran synchronously.