From 34c9b11284941505bf9210d5979de306e7ae68d8 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 9 Mar 2016 16:57:17 +0000 Subject: [PATCH] Prevent possible memory leak with restart --- .../cloud/context/restart/RestartListener.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/context/restart/RestartListener.java b/spring-cloud-context/src/main/java/org/springframework/cloud/context/restart/RestartListener.java index 4dcad0ad..5a5a4588 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/context/restart/RestartListener.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/context/restart/RestartListener.java @@ -26,7 +26,7 @@ import org.springframework.context.event.SmartApplicationListener; /** * A listener that stores enough information about an application as it starts, to be able * to restart it later if needed. - * + * * @author Dave Syer * */ @@ -57,19 +57,21 @@ public class RestartListener implements SmartApplicationListener { @Override public void onApplicationEvent(ApplicationEvent input) { if (input instanceof ApplicationPreparedEvent) { - event = (ApplicationPreparedEvent) input; - if (context == null) { - context = event.getApplicationContext(); + this.event = (ApplicationPreparedEvent) input; + if (this.context == null) { + this.context = this.event.getApplicationContext(); } } else if (input instanceof ContextRefreshedEvent) { - if (context != null && input.getSource().equals(context) && event != null) { - context.publishEvent(event); + if (this.context != null && input.getSource().equals(this.context) + && this.event != null) { + this.context.publishEvent(this.event); } } else { - if (context != null && input.getSource().equals(context)) { - context = null; + if (this.context != null && input.getSource().equals(this.context)) { + this.context = null; + this.event = null; } } }