Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

handling out of memory in chromium

I am running a web-app on a Raspberry Pi in chromium that should be running 24/7. The main issue is that it runs out of memory and displays "He's dead Jim". I am wondering if someone can help me to:

  1. Direct me to a chromium extension that will reload/ reboot the browser if memory runs out
  2. Supply a possible cron job to detect when memory is running out and reboot the browser if that's the case

The aim is to keep chromium running everyday without human intervention. So any additional methods/ideas would be appreciated. Thanks in advance!

like image 389
Lungelo Avatar asked Oct 20 '22 11:10

Lungelo


1 Answers

I actually found the culprit to be a few ajax request that each ran every few seconds to check if the server is still up or not(it's a long story but has to be done). Then I found a small memory-saving solution online: to put all the ajax requests in a variable and then clear the variable after use(I also cleared unused java-script variables application-wide). Here is an example below:

   function getData(){
        var request = $.ajax({
                url : "/someurl",
                type : "HEAD",
                dataType : "json",
                success : function(data) {
                    //use your data
                }
                error: function(){
                //doSomething
                },
                cache : false
            });


        //HERE IS THE HACK! :)
        data = null;
        request.onreadystatechange = null;
        request.abort = null;
        request = null;
        }

      setTimeout(function(){
         getData();
     }, 0.05 * 60 * 1000)
}

P.S I found the code online.

like image 168
Lungelo Avatar answered Oct 27 '22 12:10

Lungelo