> 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.
 
> Other question: Doesn't
> ==22649== 47,920 bytes in 960 blocks are indirectly lost in 
> loss record
> 920 of 921
> 
> say that there are just 47K bytes, which are scattered through 960
> blocks, that have been lost? That would make more sense to me, since
> they'd average about 50 bytes a piece, which looks about the size of a
> string. If so, the leak isn't that terrible.

Well, they're 47 kB for a short session, but in a session of several 
days/week... If I understand it correctly, we leak every single word is 
inserted in a paragraph, as we never delete them.
When valgrind says that something is "indirectly lost" means that you have, for 
instance, a tree and you deleted the root but not all the children [1]. It 
looks like our sitaution.

> Anyway, the obvious thing to do here is uncomment the code you
> identified and see if that helps.

I'll try that. Maybe we could add a bool parameter to WordList::remove to 
decide if really remove the node or just ignore it. I'd ask to the author of 
the code, sts (from svn blame), is he still active?
 
> 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.

Thanks. I hope we can defeat this and other memory leaks and make LyX more 
lightweight.
venom00

[1] http://valgrind.org/docs/manual/mc-manual.html#mc-manual.errormsgs
[2] 
http://stackoverflow.com/questions/5122963/does-setinsert-saves-a-copy-or-a-pointer-c

Reply via email to