Re: [boost] [locale] Memory leaks?

You had mistaken "reachable" code with memory leaks... Especially if some std::locale::global remains etc. It is not a bug nor even a problem. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/
________________________________ From: Jookia <166291@gmail.com> To: boost@lists.boost.org Sent: Sunday, March 3, 2013 10:19 PM Subject: [boost] [locale] Memory leaks?
Hello!
I've been debugging my application that uses Boost.Locale for the past five hours or so, and I've found it curious that it leaks memory.
In order to stop it, I have to do a couple of weird things, such as including ICU in to my projects and calling u_cleanup at the end of my application. I also have to disable certain facets. I've put all this together in some source code, that by default won't leak, but uncommenting various parts will cause it to leak:
// ---- BEGIN CODE ----------------------------------------------------
#include
#include #include <iostream> using namespace boost::locale; using namespace std;
int main() { generator gen; gen.categories( convert_facet | //collation_facet | // Various errors. //formatting_facet | // Various errors. //parsing_facet | // Various errors. message_facet | //codepage_facet | // Various errors. boundary_facet | calendar_facet | information_facet);
locale newLoc = gen("zh_CN.GB18030");
locale::global(newLoc); cout.imbue(newLoc);
// ios_info::get doesn't clean up after itself. //cout << as::date << time(0) << endl;
// Do this at the end of the program to clean up resources. locale::global(std::locale("C")); cout.imbue(std::locale("C")); u_cleanup(); }
// ---- END CODE ------------------------------------------------------
Dumping this as 'hello.cpp' and running this is how I'm debugging it:
g++ hello.cpp -lboost_locale -licuuc && valgrind --leak-check=full --show-reachable=yes ./a.out
Thanks, Jookia.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

I see. Wouldn't it be best to clean up ICU when done being used however? I have submitted a patch to trac to do this. On 08/03/13 00:02, Artyom Beilis wrote:
You had mistaken "reachable" code with memory leaks...
Especially if some std::locale::global remains etc.
It is not a bug nor even a problem.
Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/

No because if you cleanup something in ICU and than some global object that uses ICU is being destroyed after you'll get in trouble. There is no guarantee on order of destruction of global objects Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ ----- Original Message -----
From: Jookia <166291@gmail.com> To: boost@lists.boost.org Cc: Sent: Thursday, March 7, 2013 4:22 PM Subject: Re: [boost] [locale] Memory leaks?
I see. Wouldn't it be best to clean up ICU when done being used however? I have submitted a patch to trac to do this.
On 08/03/13 00:02, Artyom Beilis wrote:
You had mistaken "reachable" code with memory leaks...
Especially if some std::locale::global remains etc.
It is not a bug nor even a problem.
Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Ah. Is that the only gripe with the patch? If so, I'm happy to rework it based on the lifetime of all the ICU backends. On 08/03/13 07:27, Artyom Beilis wrote:
No because if you cleanup something in ICU and than some global object that uses ICU is being destroyed after you'll get in trouble.
There is no guarantee on order of destruction of global objects
Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/

Jookia, I don't think this is a problem at all. Reachable code is not a memory leak. The data is eventually got destroyed, also note that we as users do not really have control of how lib deallocates resources. For example this code is perfectly fine code: #include <locale> #include <iostream> struct fct : public std::locale::facet { static std::locale::id id; fct(size_t n = 0) : std::locale::facet(n) { x=new int(1); } virtual ~fct() { delete x; } int *x; }; std::locale::id fct::id; int main() { std::locale l(std::locale(),new fct(0)); std::locale::global(l); std::cout.imbue(l); } But valgrind reports reachable code... There is nothing you can do. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ ----- Original Message -----
From: Jookia <166291@gmail.com> To: boost@lists.boost.org Cc: Sent: Thursday, March 7, 2013 10:31 PM Subject: Re: [boost] [locale] Memory leaks?
Ah. Is that the only gripe with the patch? If so, I'm happy to rework it based on the lifetime of all the ICU backends.
On 08/03/13 07:27, Artyom Beilis wrote:
No because if you cleanup something in ICU and than some global object that uses ICU is being destroyed after you'll get in trouble.
There is no guarantee on order of destruction of global objects
Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Ah. I understand now. Thanks for explaining! On 08/03/13 07:39, Artyom Beilis wrote:
Jookia,
I don't think this is a problem at all. Reachable code is not a memory leak. The data is eventually got destroyed, also note that we as users do not really have control of how lib deallocates resources.
For example this code is perfectly fine code:
#include <locale> #include <iostream>
struct fct : public std::locale::facet { static std::locale::id id; fct(size_t n = 0) : std::locale::facet(n) { x=new int(1); } virtual ~fct() { delete x; } int *x; };
std::locale::id fct::id;
int main() { std::locale l(std::locale(),new fct(0)); std::locale::global(l); std::cout.imbue(l); }
But valgrind reports reachable code...
There is nothing you can do.
Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/
participants (2)
-
Artyom Beilis
-
Jookia