This makes me nervous. It works but, did I just created a subtle memory leak?
Here is the story:
I have a base class that stores vertices in a vertex array for use in OpenGL stuff. My intent is to store vertex data only once into a master object and then create instances of it and I want instances to read vertex data from the master object while keeping their own transformation matrices.
I declare a pointer to a vector array as private (since I do not want it being manipulated by anyone else except siblings)
The tricky part is I am forced to use a constructor with a default value of pointer-to-TypeGeometry.
If the object is constructed by passing it a pointer to a sibling object then this new object does not use a vertex array of its own. If it's constructor is passed the nullptr then the object creates it's own vertex array.
As you can see in the images I have to use the 'new' operator whenever the object is a master, but if I add a delete command in the destructor everything breaks.
If I omit the delete command everything works, but I worry for memory leaks. Should I worry ?
HERE is the issue: if I enable this destructor it fails.
Running fine with the destructor DISABLED. Notice only three objects were created but there are multiple calls to the destructor.
Now see what happens when the destructor is ENABLED:
std::shared_ptr
– Sander De Dycker