Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
refactoring2: improved handling of 'IChangeSerializer' instance in 'R…
Browse files Browse the repository at this point in the history
…esourceRelocationProcessor' in favor of proper memory deallocation, addresses #1048
  • Loading branch information
sailingKieler committed Apr 9, 2019
1 parent 6e29d09 commit 1608223
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<IChangeSerializer> changeSerializerProvider
@Inject ResourceRelocationStrategyRegistry strategyRegistry
@Inject ChangeConverter.Factory changeConverterFactory

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,7 +69,7 @@ public class ResourceRelocationProcessor {
private ResourceURIConverter _resourceURIConverter;

@Inject
private IChangeSerializer changeSerializer;
private Provider<IChangeSerializer> changeSerializerProvider;

@Inject
private ResourceRelocationStrategyRegistry strategyRegistry;
Expand All @@ -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<Change> _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();
}

Expand Down

0 comments on commit 1608223

Please sign in to comment.