Memory management
Another benefit of the CPU backend is its lack of manual memory management. The JavaScript runtime has a garbage collection mechanism that frees us from managing troublesome memory management. All of the objects that are created in JavaScript are tracked by the garbage collector. They are safely released once they're no longer used. Low-level programming languages such as C require us to allocate and free the memory carefully and not cause any leaks.
The CPU backend can benefit from the garbage collection of the JavaScript runtime because the data of tensors simply exists as an array of the TypedArray object of JavaScript. TypedArray is a binary buffer object in the JavaScript world. It gives us a way to access the underlying ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access