Skip to content

Commit e7eeb30

Browse files
authored
Fix StandardSofaRuntimeManager mem leak (#1373)
Signed-off-by: JermaineHua <[email protected]>
1 parent c53e51c commit e7eeb30

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/impl/ClientFactoryImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public void registerClient(Class<?> clientType, Object clientInstance) {
4040
clients.put(clientType, clientInstance);
4141
}
4242

43+
@Override
44+
public void destroy() {
45+
clients.clear();
46+
}
47+
4348
@SuppressWarnings("unchecked")
4449
@Override
4550
public <T> T getClient(Class<T> clazz) {

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/impl/StandardSofaRuntimeManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,13 @@ public void shutdown() throws ServiceRuntimeException {
112112
@Override
113113
public void shutDownExternally() throws ServiceRuntimeException {
114114
try {
115+
clientFactoryInternal.destroy();
115116
AbstractApplicationContext applicationContext = (AbstractApplicationContext) rootApplicationContext;
116117
// only need shutdown when root context is active
117118
if (applicationContext.isActive()) {
118119
applicationContext.close();
119120
}
121+
rootApplicationContext = null;
120122
appClassLoader = null;
121123
} catch (Throwable throwable) {
122124
throw new ServiceRuntimeException(ErrorCode.convert("01-03100"), throwable);

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/client/ClientFactoryInternal.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ public interface ClientFactoryInternal extends ClientFactory {
3232
* @param clientInstance client instance
3333
*/
3434
void registerClient(Class<?> clientType, Object clientInstance);
35+
36+
void destroy();
3537
}

0 commit comments

Comments
 (0)