Based on the background of C #, I only have a vague idea of ​​managing memory in C ++ - all I know is that I will have to free memory manually. As a result, my C ++ code is written in such a way that objects like std::vector , std::list , std::map freely created, used, but not freed.
I did not understand this moment until I finished my programs, now my code consists of the following types of templates:
struct Point_2 { double x; double y; }; struct Point_3 { double x; double y; double z; }; list<list<Point_2>> Computation::ComputationJob (list<Point_3>pts3D, vector<Point_2>vectors) { map<Point_2, double> pt2DMap=ConstructPointMap(pts3D); vector<Point_2> vectorList = ConstructVectors(vectors); list<list<Point_2>> faceList2D=ConstructPoints(vectorList , pt2DMap); return faceList2D; }
My question is: should I free every.single.one from using the list (in the example above, this means that I will need to free pt2DMap , vectorList and faceList2D )? That would be very tiring! I could just rewrite my Computation class so that it is less prone to memory leak.
Any idea how to fix this?
source share