Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error handling "Out of Memory Exception" in browser?

Tags:

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.

like image 761
user547794 Avatar asked Sep 18 '14 03:09

user547794


People also ask

How do I resolve out of memory exception?

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.

What does out of memory exception mean?

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.

How do you handle out of memory exception in VB net?

Throw New OutOfMemoryException() Catch e As ArgumentException Console. WriteLine("ArgumentException in String. Insert") End Try ' Execute program logic. Catch e As OutOfMemoryException Console.

Which exception is thrown when there is not enough memory?

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.


1 Answers

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; } 
like image 181
Sergiu Gordienco Avatar answered Nov 12 '22 15:11

Sergiu Gordienco