In ClassDelegate we create instances of JavaDelegate Classes. The instance is subsequently cached in the ClassDelegate-Behavior. Due to the fact that the instance is not created at parsing time but at runtime, the instance is cleared if the Behavior-Instance is removed from heap - which is good.
However, there are 3 problems:
1) if the execution hits the same Activity multiple times, under certain circumstances, the same JavaDelegate instance is reused. This potentially forces activiti-users to implement JavaDelegates in a stateless fashion (which is not documented).
2) It can lead to high memory consumption in combination with the DeploymentCache: Process Definitions are cached, which prohibits the ClassDelegate-Instances to be cleared from the heap. If users reference large object-graphs or heavy objects in a delegate, they (unconscionably) prevent a lot of memory to be freed.
3) If the delegate-class is re-deployed, the new version might not be picked up because the old instance is reused.
I propose that we do not cache DelegateInstances in ClassDelegate.
I can make the changes, but I want a core-dev to give the go-ahead and review them.