szymon talar - 2017-03-28

Hello,

I've a class like below (simplified)

Yours Find Bugs plugin throws PMB_POSSIBLE_MEMORY_BLOAT correctness error -> no way of clear or reduce the size of INSTANCES container http://fb-contrib.sourceforge.net/bugdescriptions.html

Could you please confirm if PMB_POSSIBLE_MEMORY_BLOAT applies to the WeakHashMap container?
As for the WeakHaskMap key I store only 1 hard reference to the valid connection at a time, so other invalid connections will be GC.

public class Manager {
private static final Map<connection, manager=""> INSTANCES = new WeakHashMap<>();</connection,>

public static synchronized Manager getInstanceFor(Connection connection) {
    Manager manager = INSTANCES.get(connection);
    if (manager == null) {
        manager = new Manager(connection);
        INSTANCES.put(connection, manager);
    }
    return manager;
}

private Manager(Connection connection) {
    // some constructor work here
}

}

Thank you!,
Szymon Talar