静态方法,我们正在运行到的内存泄漏问题,我们怀疑,下面的代码可能是原因,我们在一个单独的类的静态方法,并怀疑其导致内存泄漏而其直接引用。声明在辛格尔顿的Spring bean
// This class is wired in spring xml and loaded as spring bean
public class SpringSingletonRestClient{
// instance method to make a web-service call
public ServiceResponse getResponseFromARestService(String RequestParam){.....}
// public static helper bean mapping method, that is used outside this class
// for converting the service response object to different object
public static DomainResponse convertServiceResponseToDomainResponse(ServiceResponse serviceResponse){ //conversion logic.... }
}
}
使用
Class MainClass {
//injected as spring bean
SpringSingletonRestClient client;
public void someMethod(){
ServiceResponse serviceResponse = client.getResponseFromARestService(...);
DomainResponse domainResponse = SpringSingletonRestClient.convertServiceResponseToDomainResponse(serviceResponse);
// use domainResponse object
.......
.......
}
}
请让我知道,因为我刚刚加入的伪需要进一步澄清。 我们正在运行到高的内存使用情况,我们怀疑,使用它在被弹簧发起集体声明的静态方法是不正确的垃圾收集,有内存泄漏,因为它发生。
问题 - 它是坏的有一个春天发起的单例类的静态方法,即使是静态的方法是通过直接引用,而不是使用它的实例变量。
我不明白为什么使用静态方法会导致泄漏,但我应该承认,当班级是单身人士时,假设它永远不应该被收集(如果您期望的话) – 2013-02-15 19:58:37
是的,我怀疑但不太确定,直到我到达根部。 – 2013-02-15 22:20:08