Memory growth when repeatedly loading ApplicationContext with @Transactional beans lacking interfaces
29K reputation · 22 Apr 2022, 04:25 UTC
Goal: determine whether the default CGLIB proxy created for @Transactional methods on beans without interfaces causes observable memory growth when ApplicationContext instances are repeatedly instantiated in a test loop without being closed.
Uncertainty: Spring documentation notes that the proxy-target-class attribute can force JDK dynamic proxies, but the default selection remains unspecified, making it unclear if switching to JDK proxies eliminates the leak or if the leak stems from proxy lifecycle independent of context closure.
Does setting proxy-target-class to false stop the heap increase? Is the memory retention tied to the CGLIB proxy holding a reference to the target bean even after the bean is eligible for GC? What configuration yields deterministic proxy selection while preserving transactional semantics?