<commit_before>/*
 *  Copyright (c) 2018-present, Facebook, Inc.
 *
 *  This source code is licensed under the MIT license found in the LICENSE
 *  file in the root directory of this source tree.
 *
 */

package com.facebook.flipper.plugins.inspector;

import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;

public class ObjectTracker {
  ObjectTracker() {}

  private final Map<String, WeakReference<Object>> mObjects = new HashMap<>();

  void put(String id, Object obj) {
    mObjects.put(id, new WeakReference<>(obj));
  }

  @Nullable
  public Object get(String id) {
    final WeakReference<Object> weakObj = mObjects.get(id);
    if (weakObj == null) {
      return null;
    }

    final Object obj = weakObj.get();
    if (obj == null) {
      mObjects.remove(id);
    }

    return obj;<commit_msg>Use SoftReference in ObjectTracker<commit_after>/*
 *  Copyright (c) 2018-present, Facebook, Inc.
 *
 *  This source code is licensed under the MIT license found in the LICENSE
 *  file in the root directory of this source tree.
 *
 */

package com.facebook.flipper.plugins.inspector;

import java.lang.ref.SoftReference;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;

public class ObjectTracker {
  ObjectTracker() {}

  private final Map<String, SoftReference<Object>> mObjects = new HashMap<>();

  void put(String id, Object obj) {
    mObjects.put(id, new SoftReference<>(obj));
  }

  @Nullable
  public Object get(String id) {
    final SoftReference<Object> softRef = mObjects.get(id);
    if (softRef == null) {
      return null;
    }

    final Object obj = softRef.get();
    if (obj == null) {
      mObjects.remove(id);
    }

    return obj;
{'fraction_non_alphanumeric': 0.11444759206798867, 'fraction_numerical': 0.004532577903682719, 'mean_word_length': 3.482233502538071, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6081103', 'n_tokens_mistral': 548, 'n_tokens_neox': 528, 'n_words': 164}