内存泄漏
import tf from '@tensorflow/tfjs-node';
const width = 150; const height = 10; const forMemoryLeaks = [];
console.time('total time');
for (let i = 0; i < 5_000_000; i++) { tf.tidy(() => { const stateTensorTemp = tf.tensor2d([Array.from({ length: width * height }, () => Math.random())]); const stateTensor = stateTensorTemp.reshape([1, width, height]); });
if (i % 100_000 === 0) { forMemoryLeaks.push(process.memoryUsage()); console.table(forMemoryLeaks); } }
console.timeEnd('total time'); Other info / logs
bun 1.2.17 ┌────┬───────────┬───────────┬──────────┬──────────┬──────────────┐ │ │ rss │ heapTotal │ heapUsed │ external │ arrayBuffers │ ├────┼───────────┼───────────┼──────────┼──────────┼──────────────┤ │ 0 │ 335286272 │ 9522176 │ 234333 │ 40781 │ 0 │ │ 1 │ 415936512 │ 25235456 │ 17000145 │ 4817217 │ 0 │ │ 2 │ 386093056 │ 31961088 │ 22685473 │ 4853361 │ 0 │ │ 3 │ 389959680 │ 37982208 │ 28366497 │ 4901505 │ 0 │ │ 4 │ 403562496 │ 44118016 │ 34018551 │ 4925559 │ 0 │ │ 5 │ 417083392 │ 50384896 │ 39662233 │
内容来源: tensorflow/tfjs