[SciPy-user] Weave Memory Leak?

Prabhu Ramachandran prabhu_r at users.sf.net
Wed Oct 20 02:39:01 CDT 2004


>>>>> "GN" == Greg Novak <novak at ucolick.org> writes:

    GN> A few days ago I wrote the list about a memory leak in code
    GN> involving Weave.  Now I'm ready to run it up the flagpole.

    GN> I've put the code here:
    GN> http://www.ucolick.org/~novak/memory-leak.tgz

    GN> The problem is in the integrate() python function.  If I
    GN> replace it with code that doesn't use Weave (just returns
    GN> reasonable fake data), there's no memory problem.
 
I have no clue if this will help but I took a *very* quick look and
noticed that you allocate using dvector in test_derivs but don't call
free_dvector before you return.  You call test_derivs from eval_derivs
and integrate.

Try this version of test_derivs instead:

def test_derivs(eqns, yi, params, recompile):
    """Make sure that the derivs function can be evaluated"""
    code = r"""    
    double *dys = dvector(1, Nyi[0]);
    int res = derivs(0, yi-1, dys, params-1);
    free_dvector(dys, 1, Nyi[0]);

    if (res) 
      return_val = 1;
    else
      return_val = 0;
    """
    return weave.inline(code, ['yi', 'params'],
                        support_code=eqns['code'],
                        sources=['nrutil.cpp'],
                        include_dirs=[os.getcwd()],
                        headers=['"nrutil.h"'],
                        force=recompile)   


I haven't tested but my guess is that this is a top candidate for a
slow but sure memory leak.

Could that be it?

HTH.

cheers,
prabhu



More information about the SciPy-user mailing list