【JVM】spring单例内存管理简单分析
问题描述:
spring框架中controller类实例为单例
开发过程中,在controller中定义的成员变量是否添加 static 描述符,在内存管理上会有区别吗?
设计模式中单例的一个例子:
设计模式中单例的一个例子:
public
class Singleton {
private static Singleton sing = new Singleton();
private Singleton() {}
public static Singleton getInstance() {
return sing ;
}
}
设计模式里的单例内存管理情况如下:
Singleton的类信息会保存在方法区内,包括类名,类属性等
private static Singleton sing 这个静态变量也保存在方法区
new
Sin