I have a std::map
:
std::map<uint64_t, unique_ptr<struct stats>> profile_stats;
And my insert and delete functions look like this:
Insert:
WriteLock(profile_stats_lock);
profile_stats_it it = profile_stats.find(id);
if (it == profile_stats.end()) {
profile_stats[id] = unique_ptr<stats>(new stats());
}
Delete:
WriteLock(profile_stats_lock);
profile_stats_it it = profile_stats.find(id);
if (it != profile_stats.end()) {
profile_stats.erase(it);
}
Will the dynamic memory for new stats()
allocated during insert be destroyed when the iterator is erased in the delete function? Or should I do something to explicitly delete the dynamic memory being pointed to by the unique pointer?
Aucun commentaire:
Enregistrer un commentaire