如何将一个Ajax请求后,释放内存 [英] How to free memory after an Ajax request

查看:295
本文介绍了如何将一个Ajax请求后,释放内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的网站一个非常基本的AJAX幻灯片。在每一个卷轴,新的图像和响应内容不断增加的内存使用的浏览器的数量。

I have a very basic ajax slideshow on my website. On every scroll, the new images and response content continually increase the amount of memory used by the browser.

我已经做了我的研究,并尝试了所有建议,以重置每个新的请求XHR对象,但也绝对没有什么帮助。

I've done my research and tried all suggestions to reset the XHR object on each new request, but this does absolutely nothing to help.

该幻灯片是基本的,但可能包含数百个幻灯片。我希望用户能够无限期地浏览幻灯片没有崩溃的浏览器。这甚至可能?

The slideshows are basic but may contain hundreds of slides. I want a user to be able to navigate the slideshow indefinitely without crashing their browser. Is this even possible?

谢谢你,布莱恩

推荐答案

增加内存的使用情况是正常的。你来了,毕竟,装载更多的数据的每个时间 - HTML从Ajax响应,以及​​正在显示的图像。除非你使用的Adobe更为妥当Note on-生成的HTML,这只是将是一个几百HTML /文本的字节。它是将吸了大部分空间的图像。一切都得到了塞到浏览器的缓存。

Increasing memory usage is normal. You are, after all, loading more data each time - the HTML from your AJAX response, as well as the images that are being displayed. Unless you're using Adobe Pagemill-generated HTML, that's only going to be a few hundreds of bytes of HTML/text. It's the images that will suck up the most space. Everything get stuffed into the browser's cache.

因为你没有做任何幻想,与DOM(楼子树和诸如此类的东西)直接,只需更换一个HTML块重​​复,最终,浏览器会做一个清理和Chuck一些未使用的/老/陈旧形象从内存/缓存中的数据,并回收一些内存。

Since you're not doing anything fancy with the DOM (building sub-trees and whatnot) directly, just replacing a chunk of HTML repetitively, eventually the browser will do a cleanup and chuck some of the unused/old/stale image data from memory/cache and reclaim some of that memory.

现在,如果你正在做一些非常复杂的DOM操作,并产生大量的新节点上的苍蝇,并在这里和那里泄露某些节点,那么你就会有一个内存问题,因为这些泄漏的节点将最终埋葬浏览器。

Now, if you were doing some highly complex DOM manipulations and generating lots of new nodes on the fly, and were leaking some nodes here and there, THEN you'd have a memory problem, as those leaked nodes will eventually bury the browser.

不过,通过加载图像只是增加内存的使用是没有什么可担心的,它就像一个正常的扩展冲浪会话,但你只是加载了一些新的图片。

But, just increasing memory usage by loading images is nothing to worry about, it's just like a normal extended surfing session, except you're just loading some new pictures.

这篇关于如何将一个Ajax请求后,释放内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆