Quote:
A 'delete student5' statement was not added since student5 was passed to a method or constructor. Handle memory management manually.
That is one of the areas where C++ and Java differ; memory management. What this comment is telling you is that
student5
(
and other student variables) is likely to scope out here, but since this was passed to the method, this tool will not call the delete on it assuming you require this object in the outer scope as well.
Quote:
Handle memory management manually.
You should learn how C++ programs work, and how you can manage the memory. This is important if you are working with pointers (dynamically allocated memory). If you do not do that, you end up leaking memory in the system.
If you create objects locally and do not pass them around in other methods, this tool (not that I am sure of, but it) would write the
delete
statement to clean up the resources.
delete science;
This line proves the point, as may be, the
science
object was scoped only the current method, it was removed as soon as the scope finished (method body finished).
Please check these resources to learn how to manage memory in C++ programs,
Dynamic memory - C++ Tutorials[
^]
C++ Memory Management: new and delete[
^]
c++ pointer scope - Stack Overflow[
^]