Memory leak using moveNet in react native

currently I am coding a mobile with react native, expo, tf with model moveNet to perform real time pose estimation. However it shows there are memory leak occure in th GPU and I cannot find a solution.


Here is the call back function using in the TensorCamera on ready

Could anyone please help me?

Hi @Matthew_Hung welcome to the Forum.

you can use tf.dispose() for single tensors or run it inside a tf.tidy() function to avoid memory leaks.

Can you try the following line below the drawCanvas() call?

drawCanvas(poses[0]);
tf.dispose(nextImageTensor);
console.log(tf.memory());

Thank you for your advice Dennis. I have also found using start scope and endscope can solve this problem like so. Would you know if there are any differences between using dispose and scope?

const loop = async () => {
tf.engine().startScope()
const nextImageTensor = images.next().value;
try{
const poses = await detector.estimatePoses(nextImageTensor);
drawCanvas(poses[0]);
}
catch(error){
}
tf.engine().endScope()
requestAnimationFrame(loop);
}
loop();