Q:

c++ passing big vectors as output

I have several big vector (roughly with a million elements), lets say vector<int> v generated in a function or a class member function. I want to use this vector outside of this function/member efficiently, i.e., avoid copying it entirely when I pass it as an output
vector<int> make_vect() {
    vector<int> v(1e6); 
    ...      // some analysis
    return v;
}

int main() {
vector<int> v = make_vect();
}

I know that I can use a pointer to this vector vector<int> *v instead, but that would complicate things a little bit (for instance I have to delete them manually and so on). I was wondering how the code above behaves if I don't use a reference or pointer. 
Apart from copying issue, in the code above when is the allocated memory freed? Is the content never deleted unless I call v.clear()? or it automatically deletes them when there's no variable pointing to the container left? 

A:

That's exactly how you're supposed to return objects -- by value. The compiler will apply NRVO optimizations to ensure no copying takes place.

