I wonder what maximum line length I can get in Javascript, I myself tested it today on my Firefox 43.0.1 running on Windows 7. I managed to build a string 2^28 - 1 long, but when I tried to create a string with another char Firebug showed me the error "allocation overflow", which means that the line should be less than 256 MB.
Is it the same for all browsers, all computers, all operating systems, or depends on it?
I created the following snippet to find out the limit:
(function() { strings = ["z"]; try { while(true) { strings.push(strings[strings.length - 1] + strings[strings.length - 1]); } } catch(err) { var k = strings.length - 2; while(k >= 0) { try { strings.push(strings[strings.length - 1] + strings[k]); k--; } catch(err) {} } console.log("The maximum string length is " + strings[strings.length - 1].length); } })();
If you are using a different browser / OS, I would like to see your results. My result: the maximum string length is 268435455.
PS: I was looking for an answer for an answer, but the very last topic I found was from 2011, so I'm looking for more relevant information.
javascript string memory out-of-memory
Hamsterrific
source share