Bumping my old question since I can now effectively do this in 4.0 (beta), I can just create a transient object!
To prevent the object from being garbage collected when there are no more references to and from it, I can retain it in a java action with getContext().getSession().retain(object)
and it will not be garbage collected throughout my session unless I call getContext().getSession().release(objectId)
I will still need to save the identifier in a static variable somewhere so I can retrieve my object with Core.retrieveId(getContext(), objectId)
but I can simply return the object to a microflow and do the regular stuff with it in an easier way.
How about creating a MetaObject which you somehow make unique (constraints etc) and then ONLY editing/reading that object via a microflow which has "disallow concurrent execution" (to avoid race conditions).
AFAIK there is no way in which you can keep mutable state in memory. The runtime was developed so that all state was preserved in the database. If you want to keep state in memory I believe you're stuck with Java.
Just don't forget to synchronize the variable to account for race conditions ;)