c/c++ 使用valgrind檢查記憶體泄漏

来源:https://www.cnblogs.com/xiaoshiwang/archive/2020/04/14/12701947.html
-Advertisement-
Play Games

c/c++ 學習互助QQ群:877684253 本人微信:xiaoshitou5854 ...


ys@ysm:tests$ valgrind --tool=memcheck --leak-check=full ./a.out
==7503== Memcheck, a memory error detector
==7503== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==7503== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==7503== Command: ./a.out
==7503==
tid=7503, constructing 0x5c3e0b0
tid=7510, 0x5c3e0b0 name=only one
tid=7503, 0x5c3e0b0 name=only one, changed
tid=7503, constructing TestNoDestroy 0x5c3e3c0
with valgrind, you should see 1-byte memory leak.
tid=7503, destructing 0x5c3e0b0 only one, changed
==7503==
==7503== HEAP SUMMARY:
==7503==     in use at exit: 1 bytes in 1 blocks
==7503==   total heap usage: 7 allocs, 6 frees, 476 bytes allocated
==7503==
==7503== LEAK SUMMARY:
==7503==    definitely lost: 0 bytes in 0 blocks
==7503==    indirectly lost: 0 bytes in 0 blocks
==7503==      possibly lost: 0 bytes in 0 blocks
==7503==    still reachable: 1 bytes in 1 blocks
==7503==         suppressed: 0 bytes in 0 blocks
==7503== Reachable blocks (those to which a pointer was found) are not shown.
==7503== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==7503==
==7503== For counts of detected and suppressed errors, rerun with: -v
==7503== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
ys@ysm:tests$ g++ Singleton_test.cc -std=c++11 -lmuduo_base -pthread -g
ys@ysm:tests$ valgrind --tool=memcheck --leak-check=full ./a.out
==7529== Memcheck, a memory error detector
==7529== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==7529== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==7529== Command: ./a.out
==7529==
tid=7529, constructing 0x5c3e0b0
tid=7530, 0x5c3e0b0 name=only one
tid=7529, 0x5c3e0b0 name=only one, changed
tid=7529, destructing 0x5c3e0b0 only one, changed
==7529==
==7529== HEAP SUMMARY:
==7529==     in use at exit: 0 bytes in 0 blocks
==7529==   total heap usage: 6 allocs, 6 frees, 475 bytes allocated
==7529==
==7529== All heap blocks were freed -- no leaks are possible
==7529==
==7529== For counts of detected and suppressed errors, rerun with: -v
==7529== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
c/c++ 學習互助QQ群:877684253 本人微信:xiaoshitou5854


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 代碼塊:被{ }包裹起來的代碼叫代碼塊 1.局部代碼塊:寫在方法中的代碼塊 2.構造代碼塊:寫在成員位置(類中方法外)的代碼塊 3.靜態代碼塊:寫在成員位置(類中方法外)被static修飾的代碼塊 一、局部代碼塊:寫在方法中的代碼塊 作用:修改變數的作用域,提高程式的效率 變數的作用域:在變數所在的 ...
  • 前言 我們經常會看到或使用InitializingBean(或@PostConstruct)進行Bean的一個初始化過程,但是有時候會發現InitializingBean存在一些不太適用的場景。 比如我們有以下一個Dog類 @Service @Scope(scopeName = Configurab ...
  • 在Java中提供了四種訪問許可權,使用不同的訪問許可權修飾符修飾時,被修飾的內容會有不同的訪問許可權。 public:公共的。 protected:受保護的 default:預設的(空的) private:私有的 可見,public具有最大許可權。private則是最小許可權。 編寫代碼時,如果沒有特殊的考慮 ...
  • A Lucky 7 題意:一個三位數,判但是否出現數字7. 題解:簽到題。 代碼: #include<iostream> #include<algorithm> #include<cstring> #include<stdio.h> using namespace std; int main(){ ...
  • ArrayList、LinkedList和Vector源碼分析 ArrayList ArrayList是一個底層使用數組來存儲對象,但不是線程安全的集合類 ArrayList的類結構關係 ArrayList實現了List介面,List介面中定義了一些對列表通過下標進行添加刪除等方法 ArrayLis ...
  • newFixedThreadPool @Slf4j public class TheadPoolDemo { private static ThreadPoolExecutor threadPool = (ThreadPoolExecutor) Executors.newFixedThreadPoo ...
  • 為了便於SEO搜索到,首先把報錯內容貼出來吧 不同版本的Oracle驅動會報不同的錯 1 <dependency> 2 <groupId>com.oracle</groupId> 3 <artifactId>ojdbc6</artifactId> 4 <version>1.0</version> 5 ...
  • 點擊藍色“程式員書單”關註我喲 加個“星標”,每天帶你讀好書! 經過了10多年的發展,Java Web從開發框架到社區都已經非常成熟,而目前市面上最流行的Java Web框架已然是Spring全家桶,從過去的Spring,SpringMVC,再到SpringBoot。而曾經流行的JSP和servle ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...