Destruction of referenced object

A reference to a newly instantiated (in function 'A') object is passed in a call to another function, 'B', that places it into an STL map. The called function and the calling function return, the calling thread completes its work and awaits further input. After a while the calling thread runs again and function 'A' creates another object identical to the first. Once more, function 'B' puts the object into the map. Because the new object has the same key as the old object, it overwrites the old object in the map.

Is the old object destroyed when it gets overwritten, or is htere a memory leak here?
When you put an object into a map is gets copied and the copy goes into the map. The original object is destroyed when it goes out of scope.
Last edited on
What about the copy in the map? Does it destroyed when it gets overwritten?
If you insert an element with a key that already exist in the map the new element will not be added.
Thanks, Peter!
Topic archived. No new replies allowed.