I noticed a few questions, C ++ experts are asking what std :: string / std :: map / etc. should not be created using a new key (new to C ++, if this was not obvious).
So, if my understanding is correct, this will not create it on the heap, but on the stack. This would mean that at the moment when the function goes out of scope, the object will disappear, but I believe that this is not so, and my understanding is incorrect.
Is it because the base template creates an instance on the heap and manages it with auto_ptr so that it does not cause a memory leak? Does this apply to all stl classes?
In addition, the next question is what should be the approach to creating objects inserted in maps? Should they be heaped (if they are valuable outside the scope of the function)?
EDIT:
I understand the difference between the heap and the stack and the reasons for using each (I probably didn't quite understand this).
The reason I ask for this seems unnatural, just to create an instance of the object in the stack for the object that I would like to save. But, I think that is what the syntax looks like.
This means that I feel that I have something on the stack when I write,
std::map<int,int> mymap;
instead of <
std::map<int,int> *mymap = new std::map<int,int>;
I am also interested in learning about the effect of this on memory. Since the memory is now cleared by the implementation itself, is garbage collection similar in Java? Is there an implied performance impact when using the stl object?