When I use the delete keyword on an object is that objects destructor executed? What if the objected I deleted contains other pointers and I don’t delete them, is that a memory leak?
I get a confused a bit sometimes over when to use delete. The problem is worst for me when I pass things around. I don’t know when it’s safe to use delete for fear of eliminating an object that is being pointed to from somewhere else.
Yes. That’s what the destructor is for.
Yes. This is one of the most common sources of memory leaks.
This is a hard problem. There is no system that solves it perfectly, but you can get pretty far by using reference-counted smart pointers, and by reducing the number of objects that are shared.