How to avoid memory leak with shared_ptr and SWIG
问题 I'm trying to use boost::shared_ptr 's to allow for me to use c++ file I/O stream objects in my python script. However, the generated wrapper warns me that it is leaking memory. Here's a minimal .i file exhibiting the problem: %module ptrtest %include "boost_shared_ptr.i" %include "std_string.i" %shared_ptr( std::ofstream ) %{ #include <fstream> #include <boost/shared_ptr.hpp> typedef boost::shared_ptr< std::ofstream > ofstream_ptr; ofstream_ptr mk_out(const std::string& fname ){ return