Hi Juan,
The state will be purged if you return None instead of a Some.
However, this only happens when the function is called for a specific key, i.e., state won't be automatically removed after some time.
If this is your use case, you have to implement a ProcessFunction and use timers to manually clean up the state.
Best, Fabian