6

I'm trying to display images with URL.createObjectURL. However, it takes so much memory, about 10 times of image size. Here is my code:

var image = new Image();
image.src = URL.createObjectURL(blob);
image.className = 'images';
image.onload = function(){
    URL.revokeObjectURL(this.src);
};
$('.images').appendTo('body');

Is this a browser bug? Or something's wrong with my code?

user3925697
  • 609
  • 2
  • 8
  • 17

1 Answers1

10

Actually you call URL.revokeObjectURL() when you release an existing object URL which was previously created by calling window.URL.createObjectURL() for optimal performance and memory usage, if there are safe times when you can explicitly unload them.

But you can't save memory through creating object, read this answer, and this helper link.

Community
  • 1
  • 1
Mohamed Yakout
  • 2,868
  • 1
  • 25
  • 45