Closed cjvogl closed 1 month ago
Yeah, this looks like a bug in the move assignment operator of Vector.
I don't think Memory should delete on move (the semantics of Memory are like those of a pointer).
Perhaps we can just use Vector::Swap
to implement move assignment. I think that should fix this issue.
@pazner, thanks for the quick response!
I don't think Memory should delete on move (the semantics of Memory are like those of a pointer).
That makes sense.
Perhaps we can just use
Vector::Swap
to implement move assignment. I think that should fix this issue.
This also makes sense: I can implement that and test it out with the application code I'm using (unless you wanted to tackle it on your own).
Can you see if #4500 fixes the issue for you?
Works greats, thanks @pazner!
As a general musing and perhaps note to myself, I suppose a Memory
object could maintain a counter to the associated data so that the data can be deleted once there are no more Memory
objects/pointers associated with the data (something like std::shared_ptr
).
I've tracked a memory leak in application code down to the move assignment operator in the
Memory
class.I effectively have a function like
If my function is called with an assignment to an uninitialized vector like
things are all great. If my function is called to an initialized vector like
the 5 original doubles for
b
become a memory leak because the corresponding move assignment operator forVector
isand the move assignment operator for
Memory
isWhile I could modify my function signature to
void doStuff(const Vector &input, Vector &output)
, I can see others wanting to use something like the original function signature to leverage the move assignment operator forVector
. My naive fix for this is to add a line to the move assignment operator forMemory
to delete the old data, i.e.,but I can imagine this may cause some issues elsewhere?