hamishd wrote:
> Hello,
>
> In my application I create some large vectors to hold data. For
> example:
>
> std::vector<DataItemClass*> MyData;
> DataItemClass * DataItem;
>
> for(i=0;i<SomeLargeLimit;i++){
> DataItem = new DataltemClass;
> MyData.push_back(DataItem);
> }
>
>
> So while my application is running, I can watch in the "Windows Task
> Manager" under "Processes" my application's mem usage increase as I
> allocate more memory. Eg, say to 150,000KB.
>
> How do I release this memory?
>
> I go:
> for(i=0;i<MyData.size();i++)
> delete(MyData[i]);
> MyData.clear();
What does MyData.capacity() return here. clear erases the elements from
the vector, so after this code MyData.size() will return zero. However,
the memory held by the vector is not necessarily released.
If capacity does not return zero, the vector is keeping hold of its
storage space for future use, as it is allowed to do. The following
trick may help instead of calling clear (but make sure you keep your
loop that deletes all your DataItemClass objects).
std::vector<DataItemClass*>().swap(MyData);
See
http://www.gotw.ca/gotw/054.htm
Gavin Deane