CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2009
    Location
    Vienna - Austria
    Posts
    28

    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!

  2. #2
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    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.
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  3. #3
    Join Date
    Nov 2003
    Posts
    1,405

    Re: Overwriting Objects... Mem Leak?

    Quote Originally Posted by DerShodan View Post
    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.

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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.

  5. #5
    Join Date
    Jan 2009
    Location
    Vienna - Austria
    Posts
    28

    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
  •  





Click Here to Expand Forum to Full Width

Featured