fix memory leak that widgets wouldn't be deleted

This commit is contained in:
Jinhao 2017-04-28 04:18:39 +08:00
parent 155cdab511
commit 9548b87f54
4 changed files with 27 additions and 15 deletions

View File

@ -1,7 +1,7 @@
/** /**
* Nana GUI Library Definition * Nana GUI Library Definition
* Nana C++ Library(http://www.nanapro.org) * Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
* *
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
@ -59,6 +59,8 @@ namespace nana
template<typename Form, bool IsVisible = true> template<typename Form, bool IsVisible = true>
using form_loader = detail::form_loader<Form, IsVisible>; using form_loader = detail::form_loader<Form, IsVisible>;
#ifdef NANA_AUTOMATIC_GUI_TESTING
/// @brief Take control of the GUI and optionaly automaticaly tests it. /// @brief Take control of the GUI and optionaly automaticaly tests it.
/// ///
/// @detail It transfers to nana the program flow control, which begin pumping messages /// @detail It transfers to nana the program flow control, which begin pumping messages
@ -77,6 +79,9 @@ namespace nana
/// in seconds /// in seconds
void Wait(unsigned wait = 0); void Wait(unsigned wait = 0);
#else
void exec();
#endif
}//end namespace nana }//end namespace nana

View File

@ -388,8 +388,7 @@ namespace nana
{ {
if(1 == ++(fc[ttf.string()])) if(1 == ++(fc[ttf.string()]))
{ {
auto state = ::FcConfigAppFontAddFile(nullptr, reinterpret_cast<const FcChar8*>(ttf.string().c_str())); ::FcConfigAppFontAddFile(nullptr, reinterpret_cast<const FcChar8*>(ttf.string().c_str()));
state = 0;
} }
} }
else else

View File

@ -1193,6 +1193,14 @@ namespace detail
native_interface::enable_window(owner_native, true); native_interface::enable_window(owner_native, true);
} }
//Before exit of pump_event, it should call the remove_trash_handle.
//Under Linux, if the windows are closed in other threads, all the widgets handles
//will be marked as deleted after exit of the event loop and in other threads. So the
//handle should be deleted from trash before exit the pump_event.
auto thread_id = ::nana::system::this_thread_id();
wd_manager().call_safe_place(thread_id);
wd_manager().remove_trash_handle(thread_id);
lock.forward(); lock.forward();
if(0 == --(context->event_pump_ref_count)) if(0 == --(context->event_pump_ref_count))

View File

@ -28,6 +28,8 @@ namespace nana
} }
} }
#ifdef NANA_AUTOMATIC_GUI_TESTING
void click(widget& w) void click(widget& w)
{ {
std::cout << "Automatically clicking widget "<<w.caption()<<":\n"; std::cout << "Automatically clicking widget "<<w.caption()<<":\n";
@ -61,7 +63,6 @@ namespace nana
std::function<void()>f // = {} ///< emit events to mimics user actions and may asert results std::function<void()>f // = {} ///< emit events to mimics user actions and may asert results
) )
{ {
#ifdef NANA_AUTOMATIC_GUI_TESTING
std::cout << "Will wait " << wait << " sec...\n"; std::cout << "Will wait " << wait << " sec...\n";
@ -87,13 +88,12 @@ namespace nana
pump(); pump();
if (t.joinable()) if (t.joinable())
t.join(); t.join();
#else
static_cast<void>(wait);
static_cast<void>(wait_end);
static_cast<void>(f); //to eliminte unused parameter compiler warning.
pump();
#endif
} }
#else
void exec()
{
internal_scope_guard lock;
detail::bedrock::instance().pump_event(nullptr, false);
}
#endif
}//end namespace nana }//end namespace nana