首页 > 解决方案 > Python tracemalloc,什么是大小和计数?

问题描述

我正在使用 tracemalloc 库来查明我的应用程序中的内存问题。

这是我正在使用的代码。

tracemalloc.start()
            snapshot = tracemalloc.take_snapshot()
            top_stats = snapshot.statistics('lineno')
            
            numStats = len(top_stats)
            statsThreshold = 100
            if numStats < statsThreshold:
                numStatsCollections = numStats
            else: 
                numStatsCollections = statsThreshold   

            collectedStats = str(top_stats[:numStatsCollections])
            self.memLogger.error('\n----------START----------\n' +                           
            collectedStats.replace(',','\n') + '\n----------END----------\n')

示例输出如下。

[<Statistic traceback=<Traceback (<Frame filename='C:\\Users\\TheUser\\AppData\\Local\\Programs\\Python\\Python38\\lib\\base64.py' lineno=87>
)> size=10308228 count=107>
 <Statistic traceback=<Traceback (<Frame filename='C:\\Users\\TheUser\\AppData\\Local\\Programs\\Python\\Python38\\lib\\json\\decoder.py' lineno=353>
)> size=3549589 count=37774>

有人可以解释这些值的含义吗?

标签: python-3.xmemory-leakstracemalloc

解决方案


推荐阅读