E
E
enchikiben2013-11-02 15:06:40
JavaScript
enchikiben, 2013-11-02 15:06:40

Freeing memory in JS

Good evening, I load images in base64 and use js to insert the img element into the page, while it's all one element, just the picture is updated. Faced with the problem that the memory is growing, and the browser eats a lot of it, tell me how you can clear the memory in this situation? I tried to remove the picture from the dom model, it did not help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zoberg, 2013-11-02
@Zoberg

Post an example of your code on jsfiddle. A spherical example of freeing memory is as follows:

var image = "BIG DATA";
$("#container").append(image);
image = null;

You can also see in the profiler where the memory goes.
If you use jQuery and delete the image like this
document.getElementById('image').innerHTML = ''

then it can stay in jQuery.cache. See what's in there. Checking the size of jQuery.cache is a common way to find memory leaks. Again, if you're using jQuery, using native methods to remove elements remove(), empty(), html()helps avoid leaks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question