I have some question about vector release. Releasing vector storage, they said that swap is best way to release vector
vector<tempObject>().swap(tempVector);
however, if vector has struct which has variety array, how to release this vector?
struct st{
int *arr;
st(int _size){
arr = (int *)malloc(_size * sizeof(int));
}
}
vector<st> vec_st;
// pushback data
1.
vec_st.clear();
2.
for(int i =0; i < vec_st.size(); i++){
free(vec_st(i).arr);
}
is first way enough? or have to use second way? or other...?
My project running on the android using JNI. That's why I wander how to release efficiently to avoid memory problem. please help me....
ps. I don't wanna destructor. Cuz' it makes problem when used as parameter without pointer.