平时我们在写代码时候,有思考过要主动去释放vector的内存吗?
1、对于数据量不大的vector,没有必要自己主动释放vector,一切都交给操作系统。
2、但是对于大量数据的vector,在vector里面的数据被删除后,主动去释放vector的内存就变得很有必要了!
Example:
vector<string> strvec;
strvec.clear();
strvec.swap(vector<string>(strvec));
平时我们在写代码时候,有思考过要主动去释放vector的内存吗?
1、对于数据量不大的vector,没有必要自己主动释放vector,一切都交给操作系统。
2、但是对于大量数据的vector,在vector里面的数据被删除后,主动去释放vector的内存就变得很有必要了!
Example:
vector<string> strvec;
strvec.clear();
strvec.swap(vector<string>(strvec));