0

I'm using Node.js and ToolTallNate's popular node-icecast module to build a stream archiving tool for community radio stations.

It seems like all of the stream data gets stuck in memory, since the memory usage increases with disk usage.

How can we clear this stream data from memory once it's written to disk?

var fs = require('fs'),
    icecast = require('icecast');


var station = {
  shoutcast_url: 'http://streaming.streamonomy.com/xray'
};


var connectToStream = function(){

  icecast.get(station.shoutcast_url, function (res) {

    //Write to disk
    res.on('data', function(data){
      fs.appendFile('output.mp3', data, function (err) {
        if (err) throw err;
      });
    });

  })
  .on('error', function(err){
    console.error('ERROR: ' + err);
  })

}


connectToStream();
trvbr
  • 3
  • 2

1 Answers1

1

You can set data = null;, inside fs.appendFile. It still add the memory, before GC catch and release the memory. Reference.

Community
  • 1
  • 1