I have a class that is interacting with some code that takes an array
in the form of pointer to the first object and size of array as
arguments: quick example void foo(*obj o, int size )
I then have a class whose internal structure can be converted to a
primative array
Note: this is an imcomplete class just an example
class X
{
public:
Obj* object; //this is the public interface for the
function that I need to interact with
//example: foo(X.object, X.size)
int objSize; //number of objects in object array
private:
Obj* convertInternalToArray(Internal i)
};
so at some point X says:
this.object = convertInternalToArray(this.internalData)
Now convertInternalToArray creates a tempObj with the keyword new and
does the conversion and returns tempObj.
That means that when convertInternalToArray is called X.object is
pointing to memory on the heap.
Question: since tempObj only has scope in the convertInternalToArray
function I cant get access to it to delete it. If I delete this.object
in the destructor am I cleaning up the memory that was created for
tempObj and then returned to this.object.
Can someone explain to me what is happening with the memory in a
situation like this?
thanks