The cache used in BA mount service uses weakKeys() so the keys
(DOM mountpoint) could be GCed when no except cache, referenced
them).
However the values in the cache (BA mountpoint) also kept a reference
to the key, so the key was never weakly reachable and thus never GCed
resulting in a memory leak.
This is especially visible in case of frequent reconnects of netconf
mountpoints where after every reconnect a new DOM mountpoint is
created, requiring a new BA mountpoint creating new entry in the
cache of BA mount service.
This patch updates the entire suite of adapters, as it is shared
across all instances.
Change-Id: I9c109dd6d499d6185842d6a1ad5a59d75565af5c
Signed-off-by: Maros Marsalek <mmarsalek@frinx.io>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit
8ae89c54f8019f53327001d1b916a53963097b34)
@NonNullByDefault
abstract class AbstractBindingLoadingAdapter<D, K, V> extends AbstractBindingAdapter<D> {
- private final LoadingCache<K, V> proxies = CacheBuilder.newBuilder().weakKeys().build(new CacheLoader<K, V>() {
- @Override
- public V load(final K key) {
- return loadAdapter(key);
- }
- });
+ private final LoadingCache<K, V> proxies = CacheBuilder.newBuilder().weakKeys().weakValues().build(
+ new CacheLoader<K, V>() {
+ @Override
+ public V load(final K key) {
+ return loadAdapter(key);
+ }
+ });
AbstractBindingLoadingAdapter(final BindingToNormalizedNodeCodec codec, final D delegate) {
super(codec, delegate);