[Cython] Fix memory leaks in Wall and ReactorNet

The underlying C++ objects were not being deleted in the destructors for the
Python objects. Moving them to be non-pointer members of the Python wrapper
classes fixes this problem.
This commit is contained in:
Ray Speth 2013-05-31 15:55:53 +00:00
parent e059b5c60c
commit 81b8845b8e
2 changed files with 6 additions and 11 deletions

View file

@ -593,7 +593,7 @@ cdef class WallSurface:
cdef Kinetics _kinetics
cdef class Wall:
cdef CxxWall* wall
cdef CxxWall wall
cdef WallSurface left_surface
cdef WallSurface right_surface
cdef object _velocity_func

View file

@ -258,7 +258,7 @@ cdef class WallSurface:
"""
def __cinit__(self, Wall wall, int side):
self.wall = wall
self.cxxwall = wall.wall
self.cxxwall = &wall.wall
self.side = side
self._kinetics = None
@ -330,11 +330,6 @@ cdef class Wall:
temperature of the reactor it faces.
"""
def __cinit__(self, *args, **kwargs):
self.wall = new CxxWall()
self.left_surface = WallSurface(self, 0)
self.right_surface = WallSurface(self, 1)
def __init__(self, left, right, *, name=None, A=None, K=None, U=None,
Q=None, velocity=None, kinetics=(None,None)):
"""
@ -365,6 +360,9 @@ cdef class Wall:
chemistry occurs on only one side, enter ``None`` for the
non-reactive side.
"""
self.left_surface = WallSurface(self, 0)
self.right_surface = WallSurface(self, 1)
self._velocity_func = None
self._heat_flux_func = None
@ -700,12 +698,9 @@ cdef class ReactorNet:
>>> reactor_network = ReactorNet([r1, r2])
>>> reactor_network.advance(time)
"""
cdef CxxReactorNet* net
cdef CxxReactorNet net
cdef list _reactors
def __cinit__(self, *args, **kwargs):
self.net = new CxxReactorNet()
def __init__(self, reactors=()):
self._reactors = [] # prevents premature garbage collection
for R in reactors: