-
February 10th, 2009, 03:52 AM
#1
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!
-
February 10th, 2009, 04:10 AM
#2
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.
-
February 10th, 2009, 07:58 AM
#3
Re: Overwriting Objects... Mem Leak?
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.
-
February 10th, 2009, 08:29 AM
#4
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.
-
February 10th, 2009, 11:07 AM
#5
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|