What to do after exiting the middle of the fiber
Once I finished in the middle of the Fiber instance fiber
i.e. I'm yield
out of it without completing it and I don't use it anymore fiber
, what should I do with it? Should I destroy it explicitly, or is there something like kill
for fiber, or will it be garbage collected properly? If so, how does Ruby know if I will go in fiber.resume
the future or not?
source to share
You don't need to kill him if he is already dead; yield
from the fiber will do the job. You just need to make sure the fiber instance is not stored in any variables. The way you "free" them: The garbage collector works by periodically destroying an object without any reference to them. If you hold your fiber in some kind of variable, it will stay in memory until you make it inaccessible.
source to share