Is there a maximum amount of data a JavaScript application can store?
I guess this is handled by the browser and each one has its limitation?
If there isn't a limit, will a page file be created? If so, wouldn't that be insecure?
To fix JavaScript heap out of memory error, you need to add the --max-old-space-size option when running your npm command. Alternatively, you can also set the memory limit for your entire environment using a configuration file.
The 64-bit Chrome browsers are known to have a 4Gb per-tab memory limit.
JavaScript heap out of memory - how to increase the max memory for Node with max_old_space_size. If you want to increase the max memory for Node you can use --max_old_space_size option. You should set this with NODE_OPTIONS environment variable.
In Chrome and Chromium OS, the memory limit is defined by the browser, and you can inspect the limit with the following command in the Developer Tools command-line by hitting F12:
> window.performance.memory.jsHeapSizeLimit 1090519040
On my Windows 10 OS, it is about 1 GB.
On Chrom(e/ium), you can get around the heap size limit by allocating native arrays:
var target = [] while (true) { target.push(new Uint8Array(1024 * 1024)); // 1Meg native arrays }
This crashes the tab at around 2GB, which happens very rapidly. After that Chrom(e/ium) goes haywire, and repeating the test is not possible without restarting the browser.
I also recommend reading TrackJS's blogpost about Monitoring JavaScript Memory before you get deep into the weeds trying to diagnose or measure anything memory related in the browser.
You can also search comp.lang.javascript for javascript memory limit.
See also these Stack Overflow posts:
Maximum size of an Array in Javascript, which suggests you can store up to 232-1 = 4,294,967,295 = 4.29 billion elements.
Maximum number of arguments a JavaScript function can accept
There is additional knowledge on the JS9 astronomical image display library website: Dealing with Memory Limitations.
(I was trying to find a good answer, and the "there is no upper limit" answer provided here was just silly to me. I cannot run into a production issue for a multi-million dollar project and say to management, "Well, I assumed there is no upper limit and everything would be okay." Try to do a proof-of-concept, e.g. loading lots of combobox controls in your JavaScript UI framework of choice, etc. You may discover your framework has some performance degradation.)
Here are some components that I've found scale very well both in CPU performance and memory performance:
Here are some examples of frameworks with well-known performance degradation:
Here are some other things to think about:
AFAIK, there is no upper limit, your script can basically use memory until the system runs out of memory (including swap). No upper limit doesn't mean you have to eat it all, users may not like it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With