Skip to content

Standard quadrature quad() has a massive memory leak #811

@llober

Description

@llober

All memory assigned to the caches are leaked.

For example, in a code where quad() is called about 100000 times or so, it leaks 5 Gb of memory, when the normal usage - after fixing - is 60 Mb.

In quadrature.py, this fixes the issue:

class QuadratureRule(object):
...
    def clear(self):
        """
        Delete cached node data.
        """
        for dp in self.standard_cache:
            self.standard_cache[dp]=[]
        self.standard_cache = {}

        for dp in self.transformed_cache:
            self.transformed_cache[dp]=[]
        self.transformed_cache = {}

        self.interval_count = {}
...
class QuadratureMethods(object):
...
    def quad(ctx, f, *points, **kwargs):
...
        finally:
            ctx.prec = orig
            rule.clear()  # <<<<<<

        if kwargs.get("error"):
            return +v, err
        return +v

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementnew feature requests (or implementation)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions