From 1608223e05d0ab8c78d6afbd23e6a8b609ce6a90 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Tue, 9 Apr 2019 13:59:29 +0200 Subject: [PATCH] refactoring2: improved handling of 'IChangeSerializer' instance in 'ResourceRelocationProcessor' in favor of proper memory deallocation, addresses #1048 --- .../participant/ResourceRelocationProcessor.xtend | 9 ++++++++- .../participant/ResourceRelocationProcessor.java | 8 +++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/refactoring2/participant/ResourceRelocationProcessor.xtend b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/refactoring2/participant/ResourceRelocationProcessor.xtend index 39532c9969..1b2f1a190a 100644 --- a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/refactoring2/participant/ResourceRelocationProcessor.xtend +++ b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/refactoring2/participant/ResourceRelocationProcessor.xtend @@ -8,6 +8,7 @@ package org.eclipse.xtext.ui.refactoring2.participant import com.google.inject.Inject +import com.google.inject.Provider import java.util.List import java.util.Set import org.apache.log4j.Logger @@ -46,7 +47,12 @@ class ResourceRelocationProcessor { @Inject LiveScopeResourceSetInitializer liveScopeResourceSetInitializer @Accessors(PACKAGE_GETTER) @Inject LtkIssueAcceptor issues @Inject extension ResourceURIConverter - @Inject IChangeSerializer changeSerializer + + // don't hold an instance of IChangeSerializer in a field, + // as that will get blown up with temporary data (loaded resources, etc.) + // which may yield a memory leak as reported in #1048; + // hence request an instance on demand and dispose it properly + @Inject Provider changeSerializerProvider @Inject ResourceRelocationStrategyRegistry strategyRegistry @Inject ChangeConverter.Factory changeConverterFactory @@ -60,6 +66,7 @@ class ResourceRelocationProcessor { IProgressMonitor pm) throws CoreException, OperationCanceledException { if (uriChanges.empty) return null + val changeSerializer = changeSerializerProvider.get(); val resourceSet = resourceSetProvider.get(project) liveScopeResourceSetInitializer.initialize(resourceSet) val context = new ResourceRelocationContext(type, uriChanges, issues, changeSerializer, resourceSet) diff --git a/org.eclipse.xtext.ui/xtend-gen/org/eclipse/xtext/ui/refactoring2/participant/ResourceRelocationProcessor.java b/org.eclipse.xtext.ui/xtend-gen/org/eclipse/xtext/ui/refactoring2/participant/ResourceRelocationProcessor.java index 80e8c11285..9134661554 100644 --- a/org.eclipse.xtext.ui/xtend-gen/org/eclipse/xtext/ui/refactoring2/participant/ResourceRelocationProcessor.java +++ b/org.eclipse.xtext.ui/xtend-gen/org/eclipse/xtext/ui/refactoring2/participant/ResourceRelocationProcessor.java @@ -9,6 +9,7 @@ import com.google.common.base.Predicate; import com.google.inject.Inject; +import com.google.inject.Provider; import java.util.List; import java.util.Set; import java.util.function.Consumer; @@ -68,7 +69,7 @@ public class ResourceRelocationProcessor { private ResourceURIConverter _resourceURIConverter; @Inject - private IChangeSerializer changeSerializer; + private Provider changeSerializerProvider; @Inject private ResourceRelocationStrategyRegistry strategyRegistry; @@ -87,15 +88,16 @@ public Change createChange(final String name, final ResourceRelocationContext.Ch if (_isEmpty) { return null; } + final IChangeSerializer changeSerializer = this.changeSerializerProvider.get(); final ResourceSet resourceSet = this.resourceSetProvider.get(this.project); this.liveScopeResourceSetInitializer.initialize(resourceSet); - final ResourceRelocationContext context = new ResourceRelocationContext(type, this.uriChanges, this.issues, this.changeSerializer, resourceSet); + final ResourceRelocationContext context = new ResourceRelocationContext(type, this.uriChanges, this.issues, changeSerializer, resourceSet); this.executeParticipants(context); final Predicate _function = (Change it) -> { return ((!((it instanceof MoveResourceChange) || (it instanceof RenameResourceChange))) || (!this.excludedResources.contains(it.getModifiedElement()))); }; final ChangeConverter changeConverter = this.changeConverterFactory.create(name, _function, this.issues); - this.changeSerializer.applyModifications(changeConverter); + changeSerializer.applyModifications(changeConverter); return changeConverter.getChange(); }