重新加载页面是否空浏览器内存? (JavaScript)

发布于 2025-02-10 10:03:44 字数 800 浏览 2 评论 0原文

(离子)Web应用程序我有一些内存问题。

我的页面每x秒重新加载(使用setInterval,但我也尝试使用Settimeout),通过执​​行一些API调用并自行重建。页面中的数据量非常大,我有很多组件,经过几次重新加载(可能需要几个小时),我就面临着一个失误。

我已经阅读了一些问题,例如从内存出发,我将在重构代码后尝试进行一些测试。

但是,我想知道是否可以通过在某个时候“清空”浏览器内存来解决。

我真的不知道浏览器如何处理内存(我试图从浏览器在每个页面上都可以解析JavaScript吗? ,但这对我没有很大帮助),但我知道,使用JavaScript,无法关闭浏览器选项卡(未使用JS打开,即使试图欺骗浏览器,让它认为该页面是使用带有现代浏览器的JS打开的)并打开了一个新页面(我认为这将清除使用的内存,但我可能是错的)。

我想知道[硬]在某个时候重新加载页面是否会阻止内存错误(作为临时修复),或者我可以使用JavaScript做其他任何事情,以简单的方式“清除内存”更改我的代码)。

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丿*梦醉红颜 2025-02-17 10:03:44

您可以尝试运行Web应用程序,然后按CTRL+F5重新加载页面并忽略浏览器中最终的缓存内容。

我曾经在更新离子Web应用程序的版本时遇到相同的问题,并通过此解决方案解决

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

输什么也不输骨气 2025-02-17 10:03:44

如果要删除缓存,则可以尝试使用CACHE.DELETE(参数)方法,其中参数是要删除的缓存中对象/URL的键。
我不确定您在重新加载时到底做什么,所以我不能给您确切的答案,但是:
您可以在此处查找详细信息: https> https> https:// devactioner。 mozilla.org/en-us/docs/web/api/cache/delete

此外,这可能是以下内容的半dupericate:清除javascript中的缓存

我建议,您也从那里阅读了答案。

如果所有这些都失败了,并且您准备对您的代码进行更多更改:我相信使用Ajax并将响应存储仅在被重复使用的变量中存储会解决问题。

同样,根据您的重新加载方法,可以在发送的文件/数据的cachetime上设置某种到期的日期。

希望我能帮忙。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文