Overwriting Objects... Mem Leak?
Hey there!
Simple question:
Code:
private:
Vector3 destination;
...
void Entity::setDestination(const Vector3& dir) {
destination = dir;
}
...
Now what I'm actually curious about is: Does overwriting objects like this leak memory in any way?
Thanks in advance!
Re: Overwriting Objects... Mem Leak?
No.
That will only leak if a Vector3 uses dynamic memory internally and the copy assignment operator= is not implemented properly.
Re: Overwriting Objects... Mem Leak?
Quote:
Originally Posted by
DerShodan
Now what I'm actually curious about is: Does overwriting objects like this leak memory in any way?
The only time YOU can cause a leak is when you use new without a corresponding delete; That is when you allocate memory on the heap without deallocating it again.
In the code example there's no new so this code cannot cause a leak.
In Vector3 there may be a new so there may be a leak, but it's impossible to know without looking at the implementation. If YOU'VE put in a new in Vector3 without a corresponding delete you've caused it to leak.
Re: Overwriting Objects... Mem Leak?
While the above is entirely correct, note that when dealing with class members, the word "corresponding" gets more complicated than you might think.
Re: Overwriting Objects... Mem Leak?
Well thanks for the replies.
The class Vector3 is part of the Ogre 3D engine, and I would expect this to be implemented correctly. Thanks for your answers!