Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #728: Use WeakHashMap to prevent memory leaks #729

Merged
merged 1 commit into from
Apr 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.smallrye.graphql.execution.context;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

import org.dataloader.BatchLoaderContextProvider;
Expand All @@ -10,7 +9,14 @@
// hacky way to pass the SmallRyeContext from data from data fetchers to BatchLoaderEnvironment
public class SmallRyeBatchLoaderContextProvider implements BatchLoaderContextProvider {

static final Map<DataLoader, SmallRyeBatchLoaderContextProvider> INSTANCES = new ConcurrentHashMap<>();
/**
* Stores the respective SmallRyeBatchLoaderContextProvider for each DataLoader.
* <p>
* WeakHashMap is used to enable garbage collection from both once the request is complete and the DataLoader is no longer
* in use.
*/
static final Map<DataLoader, SmallRyeBatchLoaderContextProvider> INSTANCES = Collections
.synchronizedMap(new WeakHashMap<>());

public void setDataLoader(DataLoader dataLoader) {
INSTANCES.put(dataLoader, this);
Expand Down