I have some C++-Code which for some reason keeps hanging. This is the code:
using namespace std;
using namespace cv;
int main(int argc, char** argv) {
cout <<"started";
Mat im(256, 256, CV_8UC1, cv::Scalar(255));
for (int j = 0; j < 255; j++) {
for (int k = 0; k < 255; k++) {
if (k > j) {
cv::Mat black(im, cv::Rect(j, k, 1, 1));
black = cv::Scalar(0, 0, 0);
}
}
}
Mat image2;
//cvtColor(image, image2, CV_BGR2GRAY);
cout<<"started";
imshow("", im);
waitKey(0);
return 0;
}
Now, I have been trying this for 3 days now, literally erasing every single line of that code and putting it back in, it all comes down to:
must bei the imshow() which causes the program to hang so that the image does not show.
The strange thing is, I copied verbatim out of an older program of mine, it worked, even worked in the new project for a day and then SUDDENLY started hanging, meaning the program just keeps running and running without any result and it cannot be shut down.
Obviously I must be overlooking sth really basic here, but I simply cannot find it.
Help, please?
My OS is Ubuntu 15.10. Also, I just tried out SSteves answer => same problem. So it must be some kind of memory leak and not my code, right? How on earth do you fix memory leaks?