开发者

Detected a memory leak... no destructor found - for enums

This is about embedded python using swig.

I have an std::map<enum,开发者_C百科 std::string> exposed to python (embedded python). When the script is executed, swig spits out the below "warning" at the end (when the map goes out of scope - I guess):

swig/python detected a memory leak of type 'std::map< MyEnum, std::string>

... no destructor found

The .i file is:

enum MyEnum {
 ...
};

typedef std::map<MyEnum, std::string>  MyTypedef;
%template(MyTypedef) std::map<MyEnum, std::string>;

Things are ok if I replace MyEnum with int all over the code. Don't know why swig needs any special destruction when enums are not PyObjects! Am I missing something? Is there some %magic_operator which will help.

Note: I do not want to suppress the "memory leak" warning all together.

Took a hard look at the wrapper generated by swig but in vain.


Could be a problem with declaration order: the std::map %template must be declared AFTER MyEnum is added to the SWIG interface.

I have failed to do this in the past (though in my case the map key was a typedef alias to an unsigned int), and saw the exact same set of symptoms reported here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜