Skip to content

Debugging Memory Usage

angelxuanchang edited this page Jan 13, 2018 · 1 revision

Node.js

General tips: https://www.alexkras.com/simple-guide-to-finding-a-javascript-memory-leak-in-node-js/

The STK provides the function STK.util.checkMemory to log the current heap memory usage. See ssc/render.js for how to use it in your code.

Example command to loads and renders the same scene 1000 times, enables garbage collection and 10 heapdumps

   NODE_BASE_URL=http://localhost:8010 node --expose-gc ./render.js --repeat 1000 --heapdump 10 >& render.3.log

Example code for printing out memory information (does garbage collection and heapdump if requested)

   var memcheckOpts = { heapdump: { limit: cmd.heapdump } };
   STK.util.clearCache();
   STK.util.checkMemory('Processing ' + id + ' index=' + index, memcheckOpts);

Example output

   Garbage collection.. memory=211293056
   Processing 0020d9dab70c6c8cfc0564c139c82dce index=4 memory=211294336
   dump written to heapdump-15795051.360404.heapsnapshot

Once a program is running, send it SIGUSR2 to force a heapdump

   kill -s SIGUSR2 37714

Use chrome to load up the heapdumps.

Clone this wiki locally