【发布时间】:2020-08-29 21:24:17
【问题描述】:
所以我使用 Python 作为前端 GUI,它与一些 C 文件交互以作为后端进行存储和内存管理。每当 GUI 的窗口关闭或退出时,我都会为分配的变量调用所有析构函数。
是否在退出整个程序之前检查内存泄漏或可用性,例如 C Valgrind 检查,以确保没有任何内存泄漏?
示例退出:
from tkinter import *
root = Tk() # New GUI
# some code here
def destructorMethods:
myFunctions.destructorLinkedList() # Destructor method of my allocated memory in my C file
# Here is where I would want to run a Valgrind/Memory management check before closing
root.destroy() # close the program
root.protocol("WM_DELETE_WINDOW", destructorMethods) # When the close window option is pressed call destructorMethods function
【问题讨论】:
-
C 代码是你写的吗?因为到目前为止最简单的选择就是修复内存泄漏。 python 代码是否了解所有 C 分配?如果是这样,您可以在 python 中创建一个基本的垃圾收集器来跟踪您的块。
标签: python c memory-management valgrind ctypes