Hey all, I'm trying to debug a memory leak on close of someone else's code, and I wondered if it might be occurring because of the way they have their copy constructor set up. Instead of the usual reference passing, it instead contains a pointer, like so:
But the strange thing is that if SomeClass's destructor actually freed the memory, then I would expect the lack
of a correct copy constructor and/or assignment operator would not result in memory leaks, but would rather
result in heap corruptions.
there're only pointers. at your example only new will call the contructor. there will be a memory leak when no one calls delete on ptrA or ptrB (not on both of course)
Now, my question is, would that screw up any attempt you make to copy a pointer's address?
you don't use the address of the pointer just the pointer itself. that's completely ok.
Would ptrB point towards the same object as ptrA, or a copy, due to the above function?
well since you only copy the pointer so, yes, ptrB and ptrA are pointing towards the same object (and no constructor is involved)