1、示例代码
package com.memory;
/**
* @author dc
* @date 2020/6/28 - 15:29
*/
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.Proxy;
/**
* 方法区产生内存溢出错误
*/
public class MyTest4 {
public static void main(String[] args) {
while (true) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(MyTest4.class);
enhancer.setUseCache(false);
enhancer.setCallback((MethodInterceptor)(obj, method, args1, proxy) ->
proxy.invokeSuper(obj, args1));
System.out.println("Hello, World!");
enhancer.create();
}
}
}