JSONP Ajax Call with jQuery causes memory leak

I have already searched the full day and cannot find the problem of why I get such large memory leaks in a telephone conversation application that uses a large number of ajax-jsonp requests on the server.

Therefore, I broke it into the simplest example. You can find it here on jsfiddle .

Main content:

function run(){ $.ajax({ dataType: 'jsonp', url: "http://thawing-bayou-7281.herokuapp.com/test.js", success: function (res) { // some stuff here setTimeout(run, 250); } }); }; run(); 

Thus, this code invokes a jsonp api request infinitely every 250 ms.

Please note: I know this is an example that you would never have implemented! It is easy to detect memory leak.

When I run this example, the used memory grows rapidly (you can see it best on the tab of the lameness timeline). enter image description here The number of DOM nodes is also growing rapidly. At some point it breaks down (maybe some GC?), But the elements and the necessary memory are growing rapidly.

Do any of you know how to fix this problem?

Thanks!

+4
source share
1 answer

This is not a memory leak; in java, sawtooth diagrams are often found. Memory usage grows, the garbage collector gets a call, and it crashes. The graph shown is such a situation.

You will have a memory leak if the low points of the graph are constantly increasing, which is not displayed on your graph.

+4
source

Source: https://habr.com/ru/post/1495769/


All Articles