Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak in toPixels() #264

Closed
meiamsome opened this issue May 4, 2018 · 3 comments · Fixed by #3073
Closed

Memory Leak in toPixels() #264

meiamsome opened this issue May 4, 2018 · 3 comments · Fixed by #3073
Assignees
Labels
comp:core type:bug Something isn't working

Comments

@meiamsome
Copy link

TensorFlow.js version

0.10.0

Browser version

Firefox 59.0.2
Chrome 66.0.3359.139

Describe the problem or feature request

When using the toPixels() function, two extra tensors are created and are not cleaned up

Code to reproduce the bug / link to feature request

The following code outputs '0 0 2' to the console of a browser when ran.

<!DOCTYPE html>
<html>
<body>
  <canvas id='test' width='400' height='400' />
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.10.0"></script>
  <script>
  let fn = (async () => {
    let canvas = document.getElementById('test');
    let count1 = tf.memory().numTensors;
    let tensor = tf.fromPixels(canvas);
    tensor.dispose();
    let count2 = tf.memory().numTensors;
    tensor = tf.fromPixels(canvas);
    await tf.toPixels(tensor, canvas);
    tensor.dispose();
    let count3 = tf.memory().numTensors;
    console.log(count1, count2, count3);
  })();
  </script>
</body>
</html>
@nikudyshko
Copy link

Looks like memory leaks occur in tfjs-core/src/ops/array_ops.ts at lines 637-638:

    const min = (await img.min().data())[0];
    const max = (await img.max().data())[0]; 

@davidsoergel davidsoergel added type:bug Something isn't working comp:core labels May 10, 2018
@davidsoergel davidsoergel self-assigned this May 10, 2018
nsthorat pushed a commit that referenced this issue Aug 19, 2019
…s). (#264)

* Drop shelljs since it has a security issue (and no update for 6 months).

#1691

* Ignore tensorboard tests (for now) on win32.

* tensorboard and tensorBoard

* Windows cleanup message

* Add issue for reference.
@leoarc
Copy link

leoarc commented Mar 13, 2020

I am still facing this issue . One extra tensor is being assigned in tf.browser.toPixels() which I am not able to dispose . Is this issue solved ? @nsthorat @davidsoergel @rthadur

@AbdulRashidReshamwala
Copy link

This issue can be solved by

tf.engine().startScope()
tf.browser.toPixel()
tf.engine().endScope()

tested on version 1.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:core type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants