Tomcat has a cache for the parsed WebXML descriptor:
When undeployed, it seems that the cache is not cleared. In plain Tomcat it's not as harmfull as the WebXML descriptor only has some primitive informations and does not use much memory.
In case of TomEE we inherit the WebXML:
This is totally ok but it's an inner class, which holds reference to the outer OpenEJBContextConfig (which has ref to the StandardContext, therefore WebBeansContext and so on...)
I think the easiest way is to make the OpenEJBWebXml static, which fixes the bug and is more aligned with the original Tomcat design of the WebXML descriptor.
After direct undeploy, TomEE needs ~150MB. After my fix it only takes ~50MB.
It could be that Tomcat will cleanup the cache later or that Tomcat has a bug in its cleanup logic.
I will check this later but indepedent of this, we should apply my fix (PR follows) which prevents unintended behaviors when using non-static inner classes.