GithubHelp home page GithubHelp logo

Potential memory leak in Field about mimesis HOT 3 CLOSED

pedromb avatar pedromb commented on July 21, 2024
Potential memory leak in Field

from mimesis.

Comments (3)

vbuaraujo avatar vbuaraujo commented on July 21, 2024 2

From looking at the code, it seems that the problem is the usage of functools.lru_cache in https://github.com/lk-geimfari/mimesis/blob/master/mimesis/providers/base.py#L126. If I understand correctly, this is meant to load the JSON data only once, but the problem is that the cache is keyed on all function arguments, including self, which will be different for every instance. So this cache doesn't really do anything useful (each instance will load the data again), and also keeps the data from every instance around indefinitely.

A quick solution is to just remove lru_cache from this function. It won't cache anything, but the current cache is not useful anyway, and it will free memory after usage.

A possibly better solution is to move all parts of that function that don't depend on self to a staticmethod and cache the staticmethod instead.

from mimesis.

lk-geimfari avatar lk-geimfari commented on July 21, 2024 1

Well, I've fixed this issue. I've removed lru_cache since it works even faster without it. I'll release 6.0.0 soon.

from mimesis.

lk-geimfari avatar lk-geimfari commented on July 21, 2024

@vbuaraujo Correct, but instancing in the loop is absolutely unnecessary, so I'm not sure that we should do something about this problem.

from mimesis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.