Comments (3)
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:
from transitions.
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:
At 1.4 million instances, the process already consume almost 12 billion bytes (12 GB).
from transitions.
@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)
- Dynamically adding HSM to an existing state, results in child transitions to be absent.
- Mermaid diagrams HOT 4
- maximum recursion depth exceeded while calling a Python object HOT 1
- State transition during on_exception callback causes RecursionError
- "on_exception" is not invoked for "KeyboardInterrupt"
- Explicitly reexport package names
- GraphMachine: set proportional font or allow caller control HOT 3
- AttributeError: 'state' does not exist HOT 3
- prepare func raises Exception altough on_exception is defined HOT 1
- GraphMachine seems not working for parallel states HOT 1
- AsyncMachine transitions fail when a list of `State` objects are passed in to the FSM. HOT 2
- get_triggers does not work HOT 3
- Cannot use Pydantic `BaseModel` class for models HOT 2
- All possible transitions are initialized, instead of those provided as an argument. HOT 2
- Machine get into wrong state. HOT 1
- after_state_change not triggered by set_state HOT 2
- AsyncMachine with queued transitions breaks when transition is cancelled
- AsyncMachine transitions aren't atomic HOT 4
- Update COPR packages
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from transitions.