At what time should I manually run gc.collect()?
-
Should I setup a background thread to just run it every few hundred milliseconds? Is that what the automatic collector does?
Is that reliable?
https://docs.pycom.io/pycom_esp32/library/gc.html -
@BetterAuto
There is not good answer to this question.
As always it depends.But if you have infinite "main" loop
then it is good practice if you putgc.collect()at least once.
I say depends, because if you have some intensive memory operation
you probably need to run it more the times.You can also monitor
gc.mem_free()and after mem go to some level rungc.collect().You also can go in oposite direction and do not run it at all. It "should" be run automatically but then it can run in your time critical point and brake your logic.
-
Any reason not to just have it running in the background every few hundred milliseconds? It can check mem_free and auto-run. I can fork off a new thread and have it constantly run. Is that what the automatic collector does?
-
Any reason not to just have it running in the background every few hundred milliseconds?
then it can run in your time critical point and brake your logic...
better have control when and where in the code it run. -
@BetterAuto In one project I shut off automatic garbage collection and then called collect after each loop of measuring time with an ultrasound distance detector, to secure (as well as possible) that the timing wouldn't go wonky.
-
So it sounds like one risk is latency. What other risks are there from running it?
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login