The deployment cache keeps references to the process definition object tree. It directly references ExecutableScript objects, which in turn can contain instances of javax.script.CompiledScript. Such compiled scripts typically contain references to the scripting engine they were created with (this is at least the case for Nashorn and Groovy). Since CAM-3432, script engines are created on process application level, where at least a Groovy scripting engine keeps references to its context classloader, i.e. the PA classloader. So if we now undeploy the PA, the scripting engine remains referenced via the process definition and memory leaks.
Side note: this also essentially negates the effect of disabling script engine caching. A compiled script will always "cache" its creator. This can also lead to multi-threading issues if the script engine is not thread-safe.