Code Monkey home page Code Monkey logo

Comments (2)

micheles avatar micheles commented on July 24, 2024

I would not call this a memory leak. It is intended behavior, the cache is keeping references as it should. I did not want to give a complex example with weak references. Still a warning for naive programmers with wrong expectations may be in order.

from decorator.

rbu avatar rbu commented on July 24, 2024

I understand the implementation is rather naive and if you look closely, it's obvious why you made these choices. I'm trying to point out that there are ways that will come to haunt you if you use this in production. Consider the following example:

class Something(object):
    @memoize
    def expensive_object(self):
        return generate_expensive_object()

Reading this code (without knowing what memoize does), I would expect that the expensive object is cleaned up after a "Something" object goes out of scope. But it does not.

a = Something().expensive_object()
b = Something().expensive_object()
c = Something().expensive_object()

del a
del b
del c

Now there's three expensive objects and three Something objects still in existence.

from decorator.

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.