JavaScript Memory Pool implementation
$ npm install memorypool
const MemoryPool = require('memorypool');
const arrayPool = new MemoryPool(Array);
const stringPool = new MemoryPool(String);
let array1 = arrayPool.allocate();
let array2 = arrayPool.allocate();
arrayPool.free(array1);
arrayPool.free(array2);
let string1 = stringPool.allocate();
stringPool.free(string1);
// reuse Array instance from array pool
let array3 = arrayPool.allocate();
// reuse String instance from string pool
let string2 = stringPool.allocate();
new MemoryPool(type)
Constructor to create new instance of object pool.
let pool = new MemoryPool(String);
MemoryPool#allocate()
Returns an instance of type
passed on constructor.
let instance = pool.allocate();
MemoryPool#free(object: type)
Returns an object to object pool.
pool.free(instance);
MemoryPool#collect()
Clear references to collect memory by GC.
pool.collect();