Qeustion about the consumption of memory in OpenCV : Cross post [here](http://answers.opencv.org/question/178949/problem-about-the-consumption-of-memory/)
 ***
I have such simple code:

    //OpenCV 3.3.1 project
    #include<opencv.hpp>
    #include<iostream>
    using namespace std;
    using namespace cv;
    
    
    Mat removeBlackEdge(Mat img) {
    	if (img.channels() != 1)
    		cvtColor(img, img, COLOR_BGR2GRAY);
    	Mat bin, whiteEdge;
    	threshold(img, bin, 0, 255, THRESH_BINARY_INV + THRESH_OTSU);
    	rectangle(bin, Rect(0, 0, bin.cols, bin.rows), Scalar(255));
    	whiteEdge = bin.clone();
    	floodFill(bin, Point(0, 0), Scalar(0));
    	dilate(whiteEdge - bin, whiteEdge, Mat());
    	return whiteEdge + img;
    }
    int main() {               //13.0M
    	Mat emptyImg = imread("test.png", 0);   //14.7M
    	emptyImg = removeBlackEdge(emptyImg);   //33.0M
    	waitKey();
    	return 0;
    }
And this is my [test.png](http://answers.opencv.org/upfiles/15113815462075951.jpg). As the Windows show, it's size is about `1.14M`. Of course I know it will be larger when it is read in memory. But I fill cannot accept the huge consumption of memory. 
If I use F10, I can know the `project.exe` take up `13.0M`. I have nothing to say about it
When I run `Mat emptyImg = imread("test.png", 0);`, the consumption of memory is `14.7M`. It is normal also.
But why when I run `emptyImg = removeBlackEdge(emptyImg);`, the consumption of memory is up to `33.0M`??  It mean function `removeBlackEdge` cost my extra `18.3M` memory. Can anybody tell me some thing? I cannot totally accept such huge consumption of memory. Is there I miss something? I use new `emptyImg` to replace the old `emptyImg`. I think I don't need extra memory to cost?


**Ps:** If I want implement to do same thing by my `removeBlackEdge`( delete that black edge in the image), how to adjust it to cost minimum consumption of memory?
