core-async

Rachel Westmacott 2024-01-26T12:47:54.444079Z

Does anyone know if parked go blocks are eligible for garbage collection if you have no references to them?

Ben Sless 2024-01-27T08:31:56.386439Z

Not sure. A parked block means it is parked on a put or take, which are compiled to callbacks registered on a channel. So the channel has a reference to the execution state

Ben Sless 2024-01-27T08:33:49.704389Z

So seems like no, unless you also lose a lot of other related objects

Rachel Westmacott 2024-01-27T09:07:21.893489Z

In my case I am losing a lot of other related objects, so it might be fine.

Rachel Westmacott 2024-01-27T09:07:44.828599Z

I guess if I really want to know I should test it!

Joe R. Smith 2024-01-28T18:43:55.278319Z

Report back :)

Rachel Westmacott 2024-01-28T22:13:44.485219Z

It looks like, yes, you definitely can have a core.async topology get garbage collected. I achieved this by leaving the topology blocked and discarding all (strong) references to it, then requesting garbage collection. In other words it works just as you might expect with no particular issues - if you can reach it then it is kept but if you can't then it will be cleared up at the JVMs leisure. My concern had been that escaping from a completely blocked topology following an error might leave some mess, but it appears that, once abandoned, the blocked topology can be cleared up by the JVM. So that's all fine.

💯 1
Jan K 2024-01-26T12:51:28.603749Z

Yes they are

👍 1