When is a Workflow Object Garbage collected?

I read that the query method can be invoked even after the workflow has been completed.
Does this mean that the Workflow implementing Java object is kept in memory forever ?

Or
Does temporal recreate the workflow implementing object when it receives a query method ? ( Just like it recreates the object while resuming from a crash - using Event Sourcing pattern )

Or

Does temporal somehow executes the querymethod without an object of the original workflow implementing type ? ( maybe using some kind of byte code manipulation )

The Temporal recreates the workflow implementing object when it receives a query method. It works up to the namespace retention period after the workflow is completed.