I don't know if is it a good practice to define custom pools for specific operations in the application or not.
Here is an example
const mysql = require('mysql');
const pools = {};
function getPool(name) {
if (!pools[name])
pools[name] = mysql.createPool({
host: 'localhost',
user: 'root',
connectionLimit: 5,
});
return pools[name];
}
class TestClss {
constructor(i) {
this.fetched = false;
this.i = i;
}
start() {
getPool("test-pool").query("SELECT SLEEP(1);", () => {
console.log("this.i", this.i);
this.fetched = true;
})
}
}
function start() {
for (let i = 0; i < 10; i++) {
let obj = new TestClss(i);
obj.start();
}
}
start();
After all queries has been finished I took a snapshot of heap and found that 5 TestClss objects weren't garbage collected because it is has binding with query callback -> poolConnection -> pool -> pools(global variable)

I know that it will be kept until next query then replaced with new callback but the problem If I set the connection limit to large number, and has multiple pools, it will be alot of objects without beeing garbage collected.
Thanks.
Ah, I see. I believe this can be fixed, I'm taking a look.
Yea, can be fixed. The easiest fix is a change to a private property, which shouldn't be an issue (though can revisit later if it is for a different fix). But yea, I was able to reproduce and will push up a fix in just a bit to the repo.
Ok, sorry for the delay. I just pushed up the fix. Please feel free to test it out and let me know if the issue wasn't fixed. I'll release it as a patch even if I don't hear back, so don't feel pressed to test :)
@abou7mied just pushed in 2.14.1