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

296
Visualizações
Memory leak in tfjs-node code even when using tidy() and dispose()

My tfjs-node application is crashing due to running out of memory despite using tidy() and dispose() to prevent memory leaks. I've managed to reproduce the issue in the code below:

import * as tf from '@tensorflow/tfjs-node'

let x = tf.variable(tf.scalar(1))

function model(){
  for(let i = 0; i < 100; i++){
    let b = tf.tidy(() => { return tf.mul(2, 3) })
    b.dispose()
    console.log(tf.memory().numTensors)
  }
  return x
}

//this call shows just 2 tensors throughout each of model()'s iterations
model()

const optimizer = tf.train.sgd(0.001);
optimizer.minimize(() => {
  //this call shows the number of tensors increasing each iteration up to about 200
  return model()
})

Within the model() function, I loop 100 times, each time creating a tensor and then immediately calling dispose() on it. The model() function then returns a variable x.

If I call my model() function normally, the number of active tensors stays at 2 through each of the 100 iterations. This is what I expect to happen. However, when I call model() within optimizer.minimize(), it seems like the dispose() calls are just getting completely ignored. The number of tensors increases each iteration. At the end, there are roughly 200 accumulated tensors.

For this particular sample code, the memory leak isn't a big issue, but for my actual application the memory leak is huge and causes the application to crash almost immediately. Any advice on how I can fix this?

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