I'm implementing a connection pool using Apache commons pool:
the connection factory implements the PoolableObjectFactory, and the connection pool extends GenericObjectPool with such setting (just make up the number here):
setMaxIdle(10);
setMaxActive(10);
setWhenExhaustedAction(grow, WhenExhaustedAction);
setTestOnBorrow(true);
setTimeBetweenEvictionRunsMillis(1000);
setMinEvictableIdleTimeMillis(10000);
when object is destoryed or validation failed (in factory class), I set the object reference to null, hoping garbage collection will happen.
I set JVM heap memory very low (only 16MB), then try to get a lot of connections by pool.borrowObject(), and then return them to the pool:
MyConnection conn = pool.borrowObject();
// do something ....
pool.returnObject(conn);
conn = null;
Most of the time the total active and idle connection is low (only at one moment it reaches 100 objects) during my memory leak
test. However it seems the connection objects were not garbage collected and it quickly caused OutOfmemory exception.
Any advice? how come the connection objects that are set to null were not GCed? How to solve this issue? using SoftReferenceObjectPool? using weakRefObj?
Thanks!