Hello.

I have written several Javascript programs that accept user input (numbers) from a textarea box. The data then gets converted to floating point numbers for use in the actual programs.
As far as I know, the general procedure follows:
Step 1: Any data in a textarea box is by default one big string so it must be input to the Javascript program for processing as a string. Call this string TEXTAREABOXSTRING
Step 2: Split the string (separate the numbers by whitespace) up into the individual entries, placing the individual entries into a raw array of strings. Call this array RAWARRAYOFSTRINGS
Step 3: Convert all the array entries into numbers and place them in the proper numeric array for further use in the program. Call this array NUMERICARRAYTHATWILLBEUSEDINPROGRAM

Up to now, all the programs have explicitly enforced an upper limit as to the size of the numeric array that the program will accept. There is a statement on the HTML page telling users about this limit, and in the Javascript code itself there is a check to ensure the numeric array is no larger than the specified limit.

However, this check only happens at Step 3, when NUMERICARRAYTHATWILLBEUSEDINPROGRAM is filled.

I would like to try something different; I would like to start using dynamic arrays. However, I am wondering what checks to include to ensure the memory allocation can be performed. And if it cannot, how do I code the program so that it fails gracefully?

For example, say a user tries to deliberately break the program. He copies and pastes a HUGE block of numbers from an e-book. Some scenarios:
(i) TEXTAREABOXSTRING is so huge, the user doesn't have enough memory and the program fails.
(ii) The program accepts TEXTAREABOXSTRING okay, but there is not enough memory for both TEXTAREABOXSTRING and RAWARRAYOFSTRINGS. So the program fails at Step 2.
(iii) The program accepts TEXTAREABOXSTRING and RAWARRAYOFSTRINGS okay, but there is not enough memory for TEXTAREABOXSTRING, RAWARRAYOFSTRINGS, and NUMERICARRAYTHATWILLBEUSEDINPROGRAM. So the program fails at Step 3.
In fact, triple the memory is being used for the same data even though it is only the numeric array that will be used in the program (once it is filled).
Is there a way to de-allocate memory being used by TEXTAREABOXSTRING? It is not going to be used later in the program and I would like to reduce the chance that a memory allocation error might happen later.

What can I do to ensure memory allocation failures happen gracefully?
(Should I even worry about it, or is it handled internally by the browser?)