Reassign unique_ptr object with make_unique statements - Memory leak?

前端 未结 3 2145
深忆病人
深忆病人 2021-02-12 17:50

I don\'t get what following statement would do (specially second line)?

auto buff = std::make_unique(128);
buff = std::make_unique(512)         


        
3条回答
  •  名媛妹妹
    2021-02-12 18:08

    Move assignment operator is called, which does

    if (this != &_Right)
    {   // different, do the swap
        reset(_Right.release());
        this->get_deleter() = _STD move(_Right.get_deleter());
    }
    

    No leak here, as it does reset, which will deallocate.

提交回复
热议问题