检测到Swig/Python内存泄漏 [英] Swig / Python memory leak detected
问题描述
我有一个非常复杂的类,正试图在SWIG中制作Python包装器.但是,当我在Python中创建该项目的实例时,如果没有收到以下消息,便无法初始化某些数据成员:
I have a very complicated class for which I'm attempting to make Python wrappers in SWIG. When I create an instance of the item in Python, however, I'm unable to initialize certain data members without receiving the message:
>>> myVar = myModule.myDataType()
swig/python detected a memory leak of type 'MyDataType *', no destructor found.
有人知道我需要做些什么来解决这个问题吗?我可以使用一个标志来生成析构函数吗?
Does anyone know what I need to do to address this? Is there a flag I could be using to generate destructors?
推荐答案
SWIG始终生成析构器包装器(除非使用了%nodefaultdtor
指令).但是,如果对类型一无所知,它将生成一个不透明的指针包装,这将导致泄漏(以及上述消息).
SWIG always generates destructor wrappers (unless %nodefaultdtor
directive is used). However, in case where it doesn't know anything about a type, it will generate an opaque pointer wrapper, which will cause leaks (and the above message).
请检查myDataType
是SWIG已知的类型.在打开调试消息的情况下重新运行SWIG,并检查是否有任何类似于
Please check that myDataType
is a type that is known by SWIG. Re-run SWIG with debug messages turned on and check for any messages similar to
Nothing is known about Foo base type - Bar. Ignored
接收到上述消息意味着SWIG不能完全了解您的类型层次结构,因此只能对有限的信息进行操作-这可能会导致它不生成dtor.
Receiving a message as above means that SWIG doesn't know your type hierarchy to the full extent and thus operates on limited information - which could cause it to not generate a dtor.
这篇关于检测到Swig/Python内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!