When using dynamically allocated objects in C++ eg:
TGraph* A = new TGraph(...);
One should always delete
these because otherwise the objects might still be in memory when
control is handed back to the parent scope. While I can see why this is true for subscopes and subroutines of a program, does the same count for the main
scope?
Am I obliged to delete
objects that were dynamically built inside main()
? The reason why this seems a bit redudant to me is that when main
ends, the program also ends, so there is no need to worry about memory leaks.
IMO it is best to always call
delete
properly:main
scope