On 04/30/2011 09:14 PM, venom00 wrote:
>> I've looked briefly at this one before, and I find it confusing.  It
>> looks as if it is saying that we are leaking the docstring 
>> word itself,
>> i.e., that it's not being cleaned up, but why would that be?
> Mmmh, I find it pretty simple: we have some elements added to a set but never 
> removed.
I know less about this then I should. (I'm just an amateur.) But: When
we call delete d, doesn't this call the d->words_ destructor? I mean,
you can do:

    if (...) {
        set<int> tmp;
        for (int i = 0; i < 1000; ++i)
            tmp.insert(i);
    }

and there is no memory leak, because all the ints in the set are
destroyed when tmp goes out of scope. Similarly, when we delete the
pimpl, the words_ set should be deleted, and this takes care of
everything in that set. Right?

>> The other thing maybe worth trying is something simple like:
>>
>> Index: src/Paragraph.cpp
>> ===================================================================
>> --- src/Paragraph.cpp (revision 38560)
>> +++ src/Paragraph.cpp (working copy)
>> @@ -3500,12 +3500,11 @@
>>     pos_type from = pos;
>>     locateWord(from, pos, WHOLE_WORD);
>>     if (pos - from >= minlength) {
>> -     docstring word = asString(from, pos, AS_STR_NONE);
>>       FontList::const_iterator cit = d->fontlist_.fontIterator(pos);
>>       if (cit == d->fontlist_.end())
>> -       return;
>> +       break;
>>       Language const * lang = cit->font().language();
>> -     d->words_[*lang].insert(word);
>> +     d->words_[*lang].insert(asString(from, pos, AS_STR_NONE););
>>     }
>>   }
>>  }
> set<T>.insert() stores a copy [2] so you have to remove it manually. word 
> should die when goes out of scope.
>
Yes, I know it *should* die, but I was wondering if maybe it didn't for
some odd reason.

rh

Reply via email to