Giter Club home page Giter Club logo

Comments (3)

aleneum avatar aleneum commented on June 18, 2024

Hello @yw94,

it is correct that Machine contains a list of events where each Event has a reference to the machine itself. The machine reference is later passed to the model wrapped into EventData. Since Event and EventData only handle references and don't initiate machines, I don't get where this leads to memory overflow. As far as I know, Python's garbage collector is smart enough to recognise the cyclic dependency and remove machines and events. I just ran a check and created roughly 25 million instances:

from transitions import Machine
import psutil
process = psutil.Process()


class Foo:

    def __init__(self):
        self.machine = Machine(
            model=self,
            states=["a", "b"],
            transitions=[{"trigger": "a_to_b", "source": "a", "dest": "b"}],
            initial="a"
        )


counter = 0

with open("memory.csv", "w") as f:
    while True:
        counter += 1
        foo = Foo()
        if counter % 50000 == 0:
            print(f"{counter},{process.memory_info().rss}", file=f)
            f.flush()

and the memory usage (in bytes) stayed roughly the same:

Screenshot 2023-11-06 at 16 34 19

from transitions.

aleneum avatar aleneum commented on June 18, 2024

When I prevent garbage collection like this:

# ...
counter = 0
events = []
with open("memory.csv", "w") as f:
    while True:
        counter += 1
        foo = Foo()
        events.append(foo.machine.events["a_to_b"])  # <-- keep reference to an event and thus to machine
        if counter % 50000 == 0:
            print(f"{counter},{process.memory_info().rss}", file=f)
            f.flush()
# ...

the memory consumption increases rather fast:

Screenshot 2023-11-06 at 16 45 58

At 1.4 million instances, the process already consume almost 12 billion bytes (12 GB).

from transitions.

aleneum avatar aleneum commented on June 18, 2024

@yw94: I will close this issue since I cannot verify a memory leak caused by transition with information I currently have. Feel free to comment anyway if your problem persists.

from transitions.

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.