I've been working on a simple ray tracer and I'm having issues with running out of memory. I downloaded Visual Leak Detector for visual studio and it told me the following functions are causing memory leaks. I'm not sure why these would be considered leaks however:
Point* Point::copy() {
Point* result = new Point(x, y, z);
return result;
}
Point* Point::crossProduct(Point* other) {
double crossX = y*(*other).getZ() - z*(*other).getY();
double crossY = z*(*other).getX() - x*(*other).getZ();
double crossZ = x*(*other).getY() - y*(*other).getX();
Point* cross = new Point(crossX, crossY, crossZ);
return cross;
}
Note I only discovered about copy constructors after creating and using the copy function shown here. If I was going to redo the project I'd use a copy constructor instead. Now when I use the functions I make sure to call "delete" on whatever variable I'm using. For example:
Point* n = AB.crossProduct(&AC);
...
delete n;
Am I wrong in thinking that this should handle any memory leak? Is Visual Leak Detector just unable to recognize the leak has been handled because its in a separate file?