Do javascript variables have a storage limit?

Do javascript variables limit storage capacity?

I am developing one YUI datatable where I take data from a database and store it in a js object, and where necessary, I will extract it and update the YUI data. Right now in Dev I have very few records and their proper storage. In production, I can have 1000 records, is this js object able to store all these 1000 records?

If it cannot be created on a hidden text field in jsp and store the data there

+5
source share
4 answers

Yes, objects and arrays have storage restrictions. They are large enough to be theoretical for most purposes. You will be more limited by the virtual machine than by the language.

In your particular case (sending thousands of items to the client), you will encounter the same problem, whether it be JSON, JavaScript, or plain text on a JSP page: client memory. The client is much more likely to run out of system memory than you are faced with a language restriction. For thousands of small objects this should not be a problem.

Arrays have a limit of 4.2 billion elements , shown in the specification in 15.4.2.2 , for example. This is because the length is a 32-bit counter. Assuming each element is a single integer that allows you to store 16 GB of numeric data in a single array.

The semantics of objects are more complicated, but most functions for working with objects end up using arrays, so in most practical scenarios you are limited to 4.2 billion keys. Again, this is more than 16 GB of data, not counting the overhead for storing links.

The VM, and probably the garbage collector, will start hanging for a long time long before you get closer to the boundaries of the language. Some implementations will have less restrictions, especially older or interpreters. Since in most cases the JS specification does not define minimum limits, they can be defined and can be much lower ( this question is about the maximum number of arguments that are discussed).

With a good optimizing virtual machine that tries to keep track of the structures you use with this size will cause enough overhead that the VM is likely to return to using maps for your objects (it is theoretically possible to define a structure that represents a lot of data, but not very practical). Maps have a small amount of overhead, and the search time increases longer as the size increases, so you will see the performance implications: just not for any reasonable size of the object.

If you run into a different limit, I suspect that it will be 65k elements (2 ^ 16), as discussed in this answer . Finding an implementation that supports less than 65K Elements seems unlikely since most browsers were written after 32-bit architectures became the norm.

+10
source

There is no such limit. Case>

There seems to be a 16 GB limit, but you can read some tests below or in the @ssube answer.

But, probably, when your object / json is about 50 mb, you will come across strange behavior.

Here is an interesting article for Json: http://josh.zeigler.us/technology/web-development/how-big-is-too-big-for-json/

For Js Object, you have more knowledge here: the size of the maximum size of a javascript object (saying that there is no such limit, but meet strange behavior at ~ 40 mb)

+2
source

The limit depends on the available browser memory. Thus, each PC, Mac, Mobile setup will give you a different limit. I don’t know how much memory one of your records requires, but I would suggest that 1000 records should work on most machines.

But . You should avoid storing large amounts of data in simple variables, depending on the memory of the records, this slows down the behavior of the entire website. Your users with average computers can see the ugly effects of scrolling, hover delays, etc.

I would recommend you use local storage. I'm sorry that I don't know the YUI library, but I'm sure you can specify the repository for your data source.

0
source

There is a limit for javascript objects to max js object size . I would suggest using session objects because it sounds like you are trying to do it.

-1
source

All Articles