c++ - Will this code free memory allocated for MULTIMAP? -


i have multimap , pointer multimap . have multimap typedef multimap<class1, class2*> lo_index; . have lo_index * _index; points multimap. free memory spaces allocated maop performing following operation . have reset function following free memory space alocated multimap:

    ( lo_index ::iterator = _index->begin(); != _index->end(); i++ )             delete (*i).second;      // delete entries in index     _index->erase( _index->begin(), _index->end() ); 

what have read in case of set setname.clear() doesnot free allocated space . in http://www.cplusplus.com/reference/stl/multimap/erase/ found erase that

this reduces container size number of elements removed, calling each element's destructor.

so guess free allocated spaces. want confirm whether code written in reset function freeing memory or not.

for multimap, delete (*i).second can't compile because can delete objects via pointer , int not pointer.

about erase function: far concerned, entries removed container. allocator might decide not return memory, cache reuse, however, matters in limited cases.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -