The Load()
function loads some content with the adjax. In the content there is a button , when clicked, the Load()
function is called again, which again loads the same content, but with different parameters.
Question to experts: if you click on this button over 9000 times, will stack overflow
occur? My opinion is that the Load()
function in this case is not recursive and no overflow
will happen. And yours?
- If the script loads an AYAX page that loads an AYAX page, etc. - this is a recursion. There is also an obstacle in the form of pressing the button by the user, therefore, it is not necessary to consider this as recursion. - Crasher
- 3Is it really so difficult to click 9000 times and check? - Indifferent
- @Crasher, thanks for the help. The word recursion causes me to panic ever since when I picked up the MK-61 calculator in my hands. )) - Deus
- @ Indifferent, clicking is not difficult, it is difficult to see what happens with RAM. - Deus
- 2What does "Ajax loads" mean? Gives a request and exits. The request itself is executed, upon completion a callback is called, which does what is necessary and returns control. And where is the recursion? - alexlz
1 answer
Regarding the call to your function Load
: each time the function executes, displays the content and ends the work . The next call is initiated by the user by pressing the button (of course, if I understood correctly), so it can be considered - Load
works in a cycle, there can be no talk of a recursive call. But the issue of memory leak remains open. I guess this is jQuery.ajax()
. So (read to the end):
In Internet Explorer, the XmlHttpRequest object belongs to the DOM / COM world, and the Javascript function belongs to the Javascript world. Assigning xmlhttp.onreadystatechange = function () {...} sets an implicit circular link: xmlhttp refers to the function through onreadystatechange, and the function, through its scope, sees (refers to) xmlhttp.
The inability to detect and terminate such a connection in many (up to IE 6.7 June 2007 editions?) Versions of Internet Explorer leads to the fact that XmlHttpRequest along with the server response, the handler function and the entire closure are firmly in memory until the browser is rebooted.
To avoid this, a number of frameworks (YUI, dojo ...) do not put onreadystatechange at all, but instead settimeout check its readyState every 10 milliseconds. This breaks the xmlhttp <-> onreadystatechange circular bundle, and a memory leak does not threaten even the most buggy browsers.
Since all done, fail, always, and status, cover all conceivable requirements.
This generally means that the above bottleneck is not used in jQuery.ajax
.
- @ KaZac, "This generally means that the above bottleneck is not used in jQuery.ajax." - what does that mean? In $ .ajax, repeated use of Load () will still lead to memory leaks in IE? - Deus
- No, they also do not hang up the handler on onreadystatechange - zb '
- @Deus, if you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Crasher