the relevant source first as usual
import katana #my static extension module, boost code below
vector3=katana.vector3
class DummyCamera:
position=vector3(0,1,0)
view=vector3(0,0,0)
up=vector3(0,1,0)
class SuperCamera:
camera=DummyCamera()
def __init__(self):
self.gamecamera=katana.camera
self.calibrate()
def flush(self):
""" apply the changes to the game camera """
self.gamecamera.position.x = self.camera.position.x
self.gamecamera.position.y = self.camera.position.y
self.gamecamera.position.z = self.camera.position.z
self.gamecamera.up.x = self.camera.up.x
self.gamecamera.up.y = self.camera.up.y
self.gamecamera.up.z = self.camera.up.z
if not self.freelook:
self.gamecamera.view.x = self.camera.view.x
self.gamecamera.view.y = self.camera.view.y
self.gamecamera.view.z = self.camera.view.z
def update(self):
... #update the dummy camera
self.flush() #flush the changes to the real camera
and the relevant boost.python wrapper code
...
using namespace boost::python;
extern Interface* systems;
Clock & GetClock() { Clock* c=systems->clock; return *c;}
Camera & GetCamera() { Camera* c=systems->camera; return *c;}
BOOST_PYTHON_MODULE(katana)
{
class_<vector3>( "vector3", init<>() )
.def( init<vector3>() )
.def( init<float,float,float>() )
.def_readwrite( "x", &vector3::x )
.def_readwrite( "y", &vector3::y )
.def_readwrite( "z", &vector3::z )
;
class_<Interface>( ... );
class_<Camera>( "Camera", init<>() )
...
.def_readwrite( "position", &Camera::position )
.def_readwrite( "view", &Camera::view )
.def_readwrite( "up", &Camera::up )
;
class_<Clock>( ... );
return_value_policy<reference_existing_object>() );
def( "GetClock", GetClock, return_value_policy<reference_existing_object>() );
def( "GetCamera", GetCamera, return_value_policy<reference_existing_object>() );
}
...
PyRun_SimpleString("import katana");
PyRun_SimpleString("katana.clock=katana.GetClock()");
PyRun_SimpleString("katana.camera=katana.GetCamera()");
Ok. Each time I call supercamera.flush(), memory gets leaked. It typically gets called once per frame at 125 fps, and I sit back and watch my memory usage go up 20k per second in windows task manager. I dont understand why memory is being leaked.
Camera.position, .view, and .up are C++ vector3 instances. katana.camera is a c++ instance of Camera exposed to python through the GetCamera function (which is called through PyRun_SimpleString for convienence so the python user doesn''t have to call GetCamera all the time.
Thanks for any light you may shed on this, I''m stupified.
Dustin