Skip to content

Node.js + OpenCV readImage() memory leaks #411

@fabek

Description

@fabek

I have a problem with memory leaks (about 3-4MB each even cycle of this code) on node.js + opencv. I think readImage() method causes that memory issue.

Platform: BananaPi + NodeJS 0.10.29 + OpenCV 2.4.9.1

download.on('end', function(output) {
  cv.readImage(path + filename, function(err, im) {
    if (err) throw err;
    if (im.width() < 1 || im.height() < 1) throw new Error('Image has no size');
    im.detectObject('data/cascade.xml', {}, function(err, cars) {
      if (err) throw err;
      for (var i = 0; i < cars.length; i++) {
        car = cars[i];
        im.rectangle([car.x, car.y], [car.width, car.height], [0, 255, 0], 2);
      }
      im.save(path + '_' + filename);
    });
  });
});

SOLVED: nano /etc/crontab and add line:
* * * * * root sync; sync; sync; echo 3 >/proc/sys/vm/drop_caches;
It isn't beautiful, but it works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions