Question

Once I am done in the middle of a Fiber instance fiber, i.e., I yielded from it without completing it, and I am not using fiber any more, what should I do with it? Should I explicitly destroy it, or is there something like kill for a Fiber, or will it be garbage collected properly? If it is, then how does Ruby know whether I am going to fiber.resume in the future or not?

Was it helpful?

Solution

You don't have to kill it if it's already dead; yield from a fiber will do the job. You just have to make sure that the fiber instance is not stored in any variables. That's how you "free" them: the garbage collector works by periodically destroying object without any references to them. If you keep your fiber in some variable, it'll stick around in memory until you make it unreachable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top