It's await Task.yield()
which creates back-pressure, not Task.sleep()
. Sleep is there is to make deallocation even slower. It models some async shutdown activity in the deinit body.
Back-pressure is applied towards allocation of the new objects. Bounding memory usage is achieved by pausing new allocations until already scheduled deallocations are not processed. If used correctly, executors already provide this functionality. And "used correctly" means two things:
- Producing code eventually yields execution
- Deallocating tasks have equal or greater priority than allocating tasks.
Current implementation of the isolated deinit copies priority of the task that executed last deinit. If objects are allocated in high-priority task, but last release happens in low-priority task, this might be a problem. Maybe solution for both isolated and async deinit would be to remember inside the object priority of the task that allocated it, WDYT?
I was considering this in detail in separate post. Basically this makes code very hard to reason about. There are lots of sync frames inside the async function, often generated by the compiler. Which may be inlined or not.