Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

266
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda