So if you do not provide a value, to fill, it will create one using default constructor. And the descrption of that costructor says that vector is populated with copies of passed element. So: one default created original and three copies to populate vector.
In C++11 behavior of that constructor changed: if you do not provide a value, it will create them in place using default constructor. No copies ar made.
Turn on C++11 (or C++14) mode and see for yourself.
(2) fill constructor
Constructs a container with n elements. Each element is a copy of val.
Since you are using vector's fill constructor, you are making 3 copies of val. This causes "44 copy" to be emitted three times.
In the second snippet when you omit the copy constructor, the compiler provides an implicit copy constructor (without the cout). So in the second snippet, you are still calling a copy constructor 3 times in addition to the call to the default construcotr.
Where did the object with value 4 to i go? Is this memory leak?
However, after this observation and what you've explained, can I say- For fill constructor of vector, a temporary object is created using the object-constructor provided (default constructor if none available). And this temporary object is then sent to the copy constructor of that object n times as argument and the resultant n objects are contained in the vector. But the temporary object is discarded.
Are my assumptions correct and are those true for all STL containers, rather than just vector?
It is destroyed when it is not needed anymore. Make destructor output something too and see for yourself.
Is this memory leak?
No. It is almost impossible to leak automatic memory.
Are my assumptions correct and are those true for all STL containers, rather than just vector?
Yes. No. Maybe.
Not all containers have fill constructor. Also it behaves that way in outdated 1998 C++ Standard. In modern 2011 standard behavior have changed and it does not create object when it is not provided a value.