内存泄漏
ttlb 2003-08-21 03:19:24 C++Primer第六章TextQuery示例中有下面一段
for (int ix = 0; ix < elem_cnt; ++ix)
{
string textword = (*text_words)[ ix ];
// exclusion strategies
// less than 3 character or in exclusion set
if (textword.size() < 3 || exclusion_set.count(textword))
continue;
if (! word_map->count((*text_words)[ix]))
{ // not present, add it:
loc *ploc = new vector<location>;
ploc->push_back((*text_locs)[ix]);
word_map->insert(value_type((*text_words)[ix], ploc));
}
else (*word_map)[(*text_words)[ix]]->push_back((*text_locs)[ix]);
}
loc *ploc = new vector<location>;有内存泄漏,而且嵌在for循环中。
请问该如何解决?最好有代码示例,我是初学者。