DWQA QuestionsCategory: Development ToolHelp vector's memory leak problem!
DllL asked 1 month ago

Recently, I took out an algorithm in an item I wrote before. It was encapsulated as a. H file for calling. There was no problem, but when I take it out for use alone, there is a problem.
The culprit of the problem is the vector variable. Because of the project integration with the third-party open source library (openCV), the variable can only use the vector type. Then I first create a vector variable
vector<vector<Point> > contours;
findContours(input, contours, CV_RETR_TREE, CV_CHAIN_APPROX_NONE, Point(0, 0));
Then call the findcontours function of the library to put the value into the contents variable, and then do some basic queries on the contents variable. When my entire method call is finished, there will be a problem
As shown in the figure, a memory leak occurred at the end of the function I wrote. When I tried to empty the vector variable manually, this problem also occurred. It is not OK to ask me to even try to empty and then recycle the memory
vector<vector<Point> >().swap(contours);*
So I can’t think of how to solve this problem. The use of this variable is necessary, but I don’t know how to deal with this memory space at the end!!!!!!!
In addition, my development tool is from vs2013 to 2017. This algorithm was previously integrated into the MFC framework, and there was no problem.

1 Answers
cloud answered 1 month ago

Isn’t this an assertion error?
How can you tell it’s a memory leak.
Nine times out of ten, memory access is out of bounds