Friday 14 April 2017

NodeJS: Rapidly converting image with Data URI causes caching, memory leak

I am working on a software which reads a high amount of images and do processing on those images like reading their height, width etc. I came to see a very difficult situation where the memory used during converting the image url into Data URI.

request.get(imageUrl, function (error, my_data, body) {
    var imageBase64Data = new Buffer(body).toString('base64');
    var imageData = "data:" + my_data.headers["content-type"] + ";base64," + imageBase64Data;
    // using the imageData in image processing using GraphicsMagick module
});

Now the problem i am facing is when my node process starts to run and process these images, it quickly get the memory used upto 1.7GB. And the system starts giving error of memory.

I checked and learned that the buffer used to convert the image url into the Data URI does not deletes the memory once it is out of scope.

Please suggest or help how should i go further to resolve this issue.



via Indian_DEVELOPER

No comments:

Post a Comment