-
Consider this example: import idom
import time
from threading import Thread
from functools import partial
class SomeLayout:
def __init__(self):
self.ticks = 0
self.set_ticks = None
self.thread = Thread(target=self.ticker)
self.thread.start()
def ticker(self):
while True:
if self.set_ticks is not None:
self.set_ticks(self.ticks + 1)
time.sleep(0.01)
@staticmethod
@idom.component
def SomeComponent(layout):
layout.ticks, layout.set_ticks = idom.hooks.use_state(0)
def decrement_ticker(e):
layout.set_ticks(layout.ticks - 100)
return idom.html.div(
idom.html.div(idom.html.button(
{"onClick": decrement_ticker}, # remove this line to fix leak
f"Decrement ticker ({layout.ticks})"
))
)
layout = SomeLayout()
idom.run(partial(SomeLayout.SomeComponent, layout)) This is a dumbed-down version of my application. It is a dashboard-like application (i.e. it's long-running), and the issue I'm facing is that over time it leaks memory to the point it gets reaped by the OOM killer. The example above is exaggerated as the actual ticker I have is much slower (1s), but it still occurs then, just at a slower pace. If you run this example and monitor that process' memory, you should see it grow rapidly. The issue at hand seems to be the passing of the
edit: In fact, it can be reproduced without the threading and class bit. I realise this effectively triggers an infinite loop and isn't what I'd want to do in a real application, but I imagine it shouldn't be leaking memory either way? import idom
@idom.component
def SomeComponent():
ticks, set_ticks = idom.hooks.use_state(0)
set_ticks(ticks + 1)
def decrement_ticker(e):
set_ticks(ticks - 100)
return idom.html.div(
idom.html.div(idom.html.button(
{"onClick": decrement_ticker}, # removing this fixes leak
f"Decrement ticker ({ticks})"
))
)
idom.run(SomeComponent) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
This has been fixed now. See #510 The fix is included on the |
Beta Was this translation helpful? Give feedback.
This has been fixed now. See #510
The fix is included on the
0.33.2
release.