Skip to content

Instantly share code, notes, and snippets.

@dvingo
Created April 4, 2015 18:27
Show Gist options
  • Save dvingo/4cf38786ded7761941df to your computer and use it in GitHub Desktop.
Save dvingo/4cf38786ded7761941df to your computer and use it in GitHub Desktop.
create a large number of string objects in js
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>How much memory?</title>
</head>
<body>
<h1>How many JS object can we put in an array?</h1>
<script>
var x = [];
var count = 10000000;
var data = "";
var i;
for (i=0;i<count;i++) {
data += "a";
x.push({key:data});
}
setInterval(function() {
console.log('We have data: ', x.length);
console.log('x: ', x[count-1]);
console.log('data[0]: ', data[0]);
console.log('data.length: ', data.length);
}, 1000)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment