1

I'm having some memory problems with a (ionic) web application.

My page is reloading every x seconds (using setInterval but I also tried to use setTimeout) by performing some api calls and rebuilding itself. The amount of data in the page is quite huge, I have a lot of components, and after several reloads (it may takes some hours) I'm facing a Out of memory error.

I've already read some questions like JQuery refreshing page leads to browser out of memory and I will try to make some tests after refactoring code.

However, I would like to know if there could be a fix by "emptying" browser memory at some point.

I don't really know how memory is handled by browser (I tried to read something from Do browsers parse javascript on every page load? but it didn't help me a lot) but I know that with javascript it's not possible to close the browser tab (not opened with js, even trying to trick the browser to let it think the page was opened using js with modern browsers) and open a new one (which I think would clear the memory used, but I may be wrong).

I would like to know if [hard]reloading the page at some point would prevent the out of memory error (as a temporary fix) or if there is anything else i could do using javascript to "clear the memory" in a simple way without changing my code).

Ansharja
  • 1,237
  • 1
  • 14
  • 37

2 Answers2

0

You could try running the web app, then pressing CTRL+F5 to reload the page and ignoring eventual cached content in the browser.

I used to have the same problem while updating the version of a ionic web app and resolved with this solution

  • Thanks for your answer, but I was searching for a code-solutions which not requires an action from the user. Also, an explanation is welcome. – Ansharja Jun 26 '22 at 11:12
  • @Ansharja then try [this](https://stackoverflow.com/questions/2099201/javascript-hard-refresh-of-current-page), using the location.reload(true) or re-routing to the same page – Dev-it-a-dev Jun 26 '22 at 17:52
0

If you want to delete cache, you may try the cache.delete(argument) method, where the argument is the key to the object/URL in the cache you want to delete. I'm not sure what exactly you do while reloading, so I don't can't give you an exact answer, but: You can look up the specifics here: https://developer.mozilla.org/en-US/docs/Web/API/Cache/delete

Also, this may be a semi-duplicate of the following: Clear the cache in JavaScript

I suggest, you read the answers from there too.

If all that fails and you are ready to do some more changes to your code: I believe that using ajax and storing the response only in variables that are reused would solve the problem.

Also, depending on your reload-method, it could be possible to set a sort of expiry-date on the cachetime of the sent file/data.

Hope I could help.