Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

yes, you have to release your nonZeroes Mat manually. you have to trace the usage of it in your program down to where you no more need it, and release() it there.

IF the size of your inMat never changes (e.g. input from the camera), also assuming it's android, you could use this pattern:

class MyActivity {
    Mat nonzeroes; // make it a class member

    public void onCameraViewStarted(int width, int height) {
         nonZeros= Mat.zeros(height, width, CvType.CV_8UC1);
         // ... more code
    }
    public void onCameraViewStopped() {
        nonZeros.release();
        // ... more code
    }

    private Mat doSomething(Mat inMat){
        Core.findNonZero(drawnRect, nonZeros);
        return nonZeroes;
    }

yes, you have to release your nonZeroesnonZeros Mat manually. you have to trace the usage of it in your program down to where you no more need it, and release() it there.

IF the size of your inMat never changes (e.g. input from the camera), also assuming it's android, you could use this pattern:

class MyActivity {
    Mat nonzeroes; nonZeros; // make it a class member

    public void onCameraViewStarted(int width, int height) {
         nonZeros= Mat.zeros(height, width, CvType.CV_8UC1);
         // ... more code
    }
    public void onCameraViewStopped() {
        nonZeros.release();
        // ... more code
    }

    private Mat doSomething(Mat inMat){
        Core.findNonZero(drawnRect, nonZeros);
        return nonZeroes;
nonZeros;
    }