export class ObjectPool {
    free = [];
    factory;
    reset;
    constructor(factory, reset, initialSize = 256) {
        this.factory = factory;
        this.reset = reset;
        for (let i = 0; i < initialSize; i++)
            this.free.push(factory());
    }
    acquire() {
        return this.free?.pop() ?? this.factory();
    }
    release(obj) {
        this.reset(obj);
        this.free.push(obj);
    }
    get size() {
        return this.free.length;
    }
}
//# sourceMappingURL=pool.js.map