Re: ustring memory leak




On Thu, 1 Apr 2010 13:41:53 +0200
Fabian Jacquet <fabian jacquet gmail com> wrote:
If I replace Glib::ustring by std::string, I don't have the memory
leak.
Even if you include the call to Glib::thread_init() when you only use
std::string?

If so it must be related to a call to g_utf8_collate(): the
constructor Glib::ustring taking a string literal just calls the
constructor of std::string, so that can't be it, but the comparison
operator calls Glib::ustring::compare(), which calls g_utf8_collate().

Or if we are being entirely rigorous about it, just possibly when you
construct a std::string object your compiler is dispensing with the
copy constructor (which will be inline), as it is entitled but not
required to do, but does not do this when constructing a Glib::ustring
object (the constructor for which is not inline); and the copy
constructor of std::string, called by the copy constructor of
Glib::ustring, is leaking.

This seems most unlikely but you could test for it by directly
initialising the string (which in my opinion is better style anyway).

Chris
Usually Compiles invoke the Constructor, not the Copy-Constructor when using this style.

So
Glib::ustring u = "Test";
should be the same as
Glib::ustring u("Test");

Try it, but it should not change anything.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]