I am debugging a javascript/html5 web app that uses a lot of memory. Occasionally I get an error message in the console window saying
"uncaught exception: out of memory".
Is there a way for me to gracefully handle this error inside the app?
Ultimately I need to re-write parts of this to prevent this from happening in the first place.
1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.
The OutOfMemoryException is a runtime exception that tells the programmer that there is no enough memory or there is a lack of contiguous memory for the allocations required by the C# program. To avoid this exception the user should always take necessary precautions and should handle this exception.
Throw New OutOfMemoryException() Catch e As ArgumentException Console. WriteLine("ArgumentException in String. Insert") End Try ' Execute program logic. Catch e As OutOfMemoryException Console.
lang. OutOfMemoryError exception. Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap. In this case, The garbage collector cannot make space available to accommodate a new object, and the heap cannot be expanded further.
You should calclulate size of your localStorage, window.localStorage is full
as a solution is to try to add something
var localStorageSpace = function(){ var allStrings = ''; for(var key in window.localStorage){ if(window.localStorage.hasOwnProperty(key)){ allStrings += window.localStorage[key]; } } return allStrings ? 3 + ((allStrings.length*16)/(8*1024)) + ' KB' : 'Empty (0 KB)'; }; var storageIsFull = function () { var size = localStorageSpace(); // old size // try to add data var er; try { window.localStorage.setItem("test-size", "1"); } catch(er) {} // check if data added var isFull = (size === localStorageSpace()); window.localStorage.removeItem("test-size"); return isFull; }
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