Correctly track memory for image pyramid functions

This commit is contained in:
David Starke 2018-01-17 14:55:57 -08:00
parent 9646626e3d
commit e1c0d8ef4e
2 changed files with 43 additions and 0 deletions

View File

@ -2180,14 +2180,20 @@ NAN_METHOD(Matrix::WarpAffine) {
NAN_METHOD(Matrix::PyrDown) {
SETUP_FUNCTION(Matrix)
int oldSize = self->mat.dataend - self->mat.datastart;
cv::pyrDown(self->mat, self->mat);
int newSize = self->mat.dataend - self->mat.datastart;
Nan::AdjustExternalMemory(newSize - oldSize);
return;
}
NAN_METHOD(Matrix::PyrUp) {
SETUP_FUNCTION(Matrix)
int oldSize = self->mat.dataend - self->mat.datastart;
cv::pyrUp(self->mat, self->mat);
int newSize = self->mat.dataend - self->mat.datastart;
Nan::AdjustExternalMemory(newSize - oldSize);
return;
}

View File

@ -825,6 +825,43 @@ test("Matrix reshape", t=>{
t.end();
});
test("Matrix pyrDown", t=>{
gc();
var startingMemory = process.memoryUsage().external;
var image = new cv.Matrix(100, 100, cv.Constants.CV_8UC3, [0,0,0]);
t.equal(process.memoryUsage().external - startingMemory, 30000); //100 * 100 * 3
image.pyrDown();
t.equal(process.memoryUsage().external - startingMemory, 7500); //50 * 50 * 3
image.release();
var endingMemory = process.memoryUsage().external;
t.equal(endingMemory - startingMemory, 0);
t.end();
});
test("Matrix pyrUp", t=>{
gc();
var startingMemory = process.memoryUsage().external;
var image = new cv.Matrix(100, 100, cv.Constants.CV_8UC3, [0,0,0]);
t.equal(process.memoryUsage().external - startingMemory, 30000); //100 * 100 * 3
image.pyrUp();
t.equal(process.memoryUsage().external - startingMemory, 120000); //200 * 200 * 3
image.release();
var endingMemory = process.memoryUsage().external;
t.equal(endingMemory - startingMemory, 0);
t.end();
});
//********************
// Additional Asynchronous Matrix Functions
//********************