Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fabek opened this issue May 25, 2016 · 3 comments
Open

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

fabek opened this issue May 25, 2016 · 3 comments

Comments

@fabek
Copy link

fabek commented May 25, 2016

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.

@Queuecumber
Copy link
Collaborator

You can try freeing the memory yourself using the release method

On Wed, May 25, 2016, 06:49 fabek [email protected] wrote:

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);
});
});
});


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#411

@fabek
Copy link
Author

fabek commented May 29, 2016

No, I can't under Javascript. im.release() doesn't work anymore. It's possible under C++ only.

@Queuecumber
Copy link
Collaborator

Why do you think that? Was it broken recently or something?

On Sun, May 29, 2016, 08:14 fabek [email protected] wrote:

No, I can't under Javascript. im.release() doesn't work anymore. It's
possible under C++ only.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#411 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AFl_q3ec_CuGAYdqBEQEseQX1XhSMs39ks5qGYM9gaJpZM4ImZ9f
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants