在我的主要功能,我用新創建三個對象。然後我刪除它們。通過Valgrind運行顯示8個字節的可達內存。我試圖在一個循環中粘貼整個主函數,以便運行多次。它仍然只有8個字節。仍然可達內存全部在範圍指針釋放
我的主 -
int main()
{
settings *st = new settings();
thread_data *td = new thread_data(st);
client_handler *cl = new client_handler(td);
delete cl;
delete td;
delete st;
}
有關Valgrind的輸出 -
==24985== 8 bytes in 1 blocks are still reachable in loss record 1 of 1
==24985== at 0x4C2CD7B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==24985== by 0x4E494F9: boost::detail::get_once_per_thread_epoch() (in /usr/lib/libboost_thread.so.1.49.0)
==24985== by 0x4E4182F: ??? (in /usr/lib/libboost_thread.so.1.49.0)
==24985== by 0x4E41B08: boost::detail::get_current_thread_data() (in /usr/lib/libboost_thread.so.1.49.0)
==24985== by 0x4E41D58: boost::this_thread::interruption_enabled() (in /usr/lib/libboost_thread.so.1.49.0)
==24985== by 0x4E41D88: boost::this_thread::disable_interruption::disable_interruption() (in /usr/lib/libboost_thread.so.1.49.0)
==24985== by 0x421854: boost::shared_mutex::lock_upgrade() (shared_mutex.hpp:195)
==24985== by 0x423A3B: boost::upgrade_lock<boost::shared_mutex>::lock() (locks.hpp:875)
==24985== by 0x422FA6: boost::upgrade_lock<boost::shared_mutex>::upgrade_lock(boost::shared_mutex&) (locks.hpp:766)
==24985== by 0x41E15C: settings::load() (settings.cpp:91)
==24985== by 0x41D796: settings::settings() (settings.cpp:34)
==24985== by 0x40A3BB: main (main.cpp:26)
設置::負載()被調用一次,從構造函數。 91行是第一行 -
bool settings::load()
{
boost::upgrade_lock<boost::shared_mutex> lock(_access);
boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
我不明白如何仍然可以訪問內存。設置對象被刪除。當設置構造函數被調用時(它是設置的成員),應該刪除_access。我試圖改變_access指針&分配/刪除在構造/析構函數無濟於事。 升級鎖定超出範圍時應解構。
即使存在內存泄漏(據我所知,boost :: thread(版本1.49)中沒有已知錯誤),內存應該丟失嗎?
我知道這是不是一個大問題,但它是一個刺激(和對等是不是讓我忘掉它)
任何想法?
這篇文章[鏈接](http://stackoverflow.com/questions/6321602/boost-thread-leakage-c)似乎有關,但我和我的返回所以會想當然地認爲他們應該的valgrind之前已經退出之前的所有線程?特別是因爲這個呼叫來自主要。 – Hector