Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

257
Vistas
Nodejs genetic algorithm memory management?

I'm trying to implement a genetic algorithm and have the problem of heap memory getting too large. To the extend that it throws an error. I'm afraid it has something to do with my population array. I displayed the memory usage while running the program and recognized it is growing and growing and never gets freed up.

Consider the following setup:

let used = {}

class Trainer {
    static breed = function(elite) {
        //code for making a new generation
        return brood
    }
    constructor() {
        this.population = []
    }
    async evolve(data, options, callback) {
        // potential point where the error may be
        // because I see the memory growing and never getting smaller
        // but I think it should get smaller because I don't
        // reference the old generation any more or do I ?
        while (error >= threshold) {
            // train each member of the population async
            // and than make a new population out of the elite
            const elite = this.population.slice(0, 10)
            this.population = Trainer.breed(elite) <--- ¯\_(ツ)_/¯
            callback(info)
            used = process.memoryUsage()
        }
    }
}

const trainer = new Trainer
const data = getData()
const options = makeOptions()

function log(info) {
    console.log(info)
    console.log(used)
}

async function test() {
    await trainer.evolve(data, options, log)
}

test()

Now I have some questions.

Is it true that on each generation the old array is not referenced anymore and get's garbage collected and makes some free space in memory?

How can I analyze the memory usage by each function to get better inside of where the problem may is in my code?

Because the code is very large I tried to simplified my problem. But if you are interested in the complete code please have a look in my repo: https://github.com/kiro7shiro/image-generator You can find the described setup from above in the "/cli/image-generator-evolve.js" file.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda