On Tue, May 17, 2016 at 12:48 AM, Alain Stalder <[email protected]> wrote:
>
> On 17.05.16 09:04, Alain Stalder wrote:
>
> PS: Note that Introspector.flushFromCaches(clazz) was experimentally
> really not necessary in this case, but maybe has to do with the simple
> nature of the test script ("42") and only calling a (no-args)
> constructor... In any case very promising...
>
>
> Ah, that's simply because it is already called in
> InvokerHelper.removeClass():
>
> public static void removeClass(Class clazz) {
> metaRegistry.removeMetaClass(clazz);
> ClassInfo.remove(clazz);
> Introspector.flushFromCaches(clazz);
> }
>
> Experimentally, for the test with ClassGCTester, the first call
> (metaRegistry.removeMetaClass(clazz)) was not necessary to have garbage
> collection before Metaspace reaches the maximum, the other two were.
>
>
I believe the removeMetaClass call is only there in case the metaclass
changed. Any added methods cause the weak metaclass to be replaced by a
strong metaclass (ExpandoMetaClass) and that has a strong ref to the class
requiring removing the metaclass in order to allow GC to work.