var express = require('express');
var app = require('http').createServer()
var io = require('socket.io')(app);
var Twitter = require('twitter');
var client = new Twitter({
consumer_key: '***',
consumer_secret: '***',
access_token_key: '***',
access_token_secret: '***'
});
var questions = result = [];
app.listen(process.env.PORT || 3000);
io.on('connection', function (socket) {
var params = {q:encodeURIComponent('#javascript'),result_type:'recent','count':10};
client.get('search/tweets', params, function(error, tweets, response){
var tweet = tweets.statuses;
for (var i = 0; i < tweet.length; i++)
questions.push(tweet[i].text+'|https://twitter.com/chuckdowe/status/'+tweet[i].id);
socket.emit('tweets', JSON.stringify(questions));
});
setInterval(function(){
var params = {q:encodeURIComponent('#javascript'),result_type:'recent','count':10};
client.get('search/tweets', params, function(error, tweets, response){
var tweet = tweets.statuses;
var arr = [];
for (var i = 0; i < tweet.length; i++)
for (var z = 0; z < questions.length; z++ )
if (questions[z].indexOf(tweet[i])<0)
{
arr.push(tweet[i].text+'|https://twitter.com/chuckdowe/status/'+tweet[i].id);
questions.push(tweet[i].text+'|https://twitter.com/chuckdowe/status/'+tweet[i].id);
}
socket.emit('newtweets', JSON.stringify(arr));
});
},10000);
});
Ошибка:
<--- Last few GCs --->
20804 ms: Scavenge 1397.5 (1456.2) -> 1397.5 (1456.2) MB, 0.4 / 0 ms (+ 5.3 ms in 1 steps since last GC) [allocation failure] [incremental marking delaying mark-sweep].
22013 ms: Mark-sweep 1397.5 (1456.2) -> 1397.5 (1456.2) MB, 1208.6 / 0 ms (+ 37.4 ms in 253 steps since start of marking, biggest step 5.3 ms) [last resort gc].
23181 ms: Mark-sweep 1397.5 (1456.2) -> 1397.5 (1456.2) MB, 1167.9 / 0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x3a56eae37399 <JS Object>
1: indexOf(aka indexOf) [native string.js:~76] [pc=0x3fce247d9e7e] (this=0x1ef5e34fdb11 <String[169]: JavaScriptDaily: JavaScript Performance Updates in Microsoft Edge and Chakra: https://t.co/CvltapIweb #javascript|https://twitter.com/chuckdowe/status/747463523672948700>,z=0x30710d6fcd81 <an Object with map 0x9e53aa6e589>)
2: /* anonymous */(aka /* anonymous */) [/Applications/MAMP/htd...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
Abort trap: 6
В чем проблема? Я заметил, что это бывает, когда я работаю с массивом.