今天在解決客戶的一個內存泄露的問題,客戶提供了source code,但從代碼語法,代碼結構上的檢查,都沒有發現什麼問題,編碼風格還算整潔,那爲什麼還有Memory Leak?
客戶代碼有一個特點,使用了多線程,而且用得還比較頻繁,而且初看代碼,也沒有問題,線和有創建pthread_create, 都會有退出pthread_exit,那問題在那裏,於是,就查看了下linux的api手冊,仔細研究了下linux 的thread.
##Linux如此說
A thread may either be joinable or detached. If a thread is joinable, then another thread can call
pthread_join(3) to wait for the thread to terminate and fetch its exit status. Only when a terminated joinable
thread has been joined are the last of its resources released back to the system. When a detached thread termi‐
nates, its resources are automatically released back to the system: it is not possible to join with the thread in
order to obtain its exit status. Making a thread detached is useful for some types of daemon threads whose exit
status the application does not need to care about. By default, a new thread is created in a joinable