Opt out of last* derived state
See original GitHub issueI have a number of service and controller tasks that return very large data structures (blobs, JSZip objects, etc.), which are then processed and discarded. But they are unable to be garbage collected because they are held in memory by the task scheduler’s various last*
properties, and since the tasks are on singletons, the memory can’t be freed until the task is run again (and it’s replaced with a similarly large data structure).
What I’d really like is a way to opt out of the last*
derived state on a task-by-task basis, perhaps something like:
foo: task(function*() {
// ...
}).withoutLastState()
When this lands it would give me a public mechanism to dump that data, but I’d have to do it at each call site of the task, rather than encapsulating it in the task itself. Currently I don’t think there’s any way to recover that memory other than some pretty ugly workarounds (or going back to an async function with a bunch of this.isDestroyed
checks 😦)
If this sounds reasonable and we agree on an API, I’d be happy to PR the changes. I could also write an RFC if more clarification/formal discussion is needed.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
@machty for me it’s about memory consumption – I have tasks that fetch very large files, load them into JSZip objects, and return them as their result. The application extracts data from them and then discards the JSZip objects, so the fact that the derived state keeps a reference to the result of the last task instance (as well as the arguments I think) pins very large data objects in memory. It’s a fairly specific use case, but adds up to a lot of unnecessary memory consumption in my app.
That’s why ideally I’d have the ability to keep the
isRunning
and all that, but not hold only to any values (arguments/return values), which I think requires not holding onto any task instances because their scopes often hold references to values.onState
is now documented as a modifier to the decorator: https://ember-concurrency.com/api/global.html#task.As an aside, I’m working on an RFC to make
TaskFactory
a public API as well, and will do some thinking about setting defaults.