Use SoftReference in ObjectTracker
Summary: if we use WeakReferences, DebugSection nodes are released very fast and highlighting doesn't work because the node is removed from the ObjectTracker. passy do you know who else I can add as reviewer? Reviewed By: passy Differential Revision: D14385872 fbshipit-source-id: ecc63190a84a7186296ed9c4c82ff6ab2aca8ad2
This commit is contained in:
committed by
Facebook Github Bot
parent
2f3678d6e3
commit
50a1fa64d8
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
package com.facebook.flipper.plugins.inspector;
|
package com.facebook.flipper.plugins.inspector;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.SoftReference;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -16,20 +16,20 @@ import javax.annotation.Nullable;
|
|||||||
public class ObjectTracker {
|
public class ObjectTracker {
|
||||||
ObjectTracker() {}
|
ObjectTracker() {}
|
||||||
|
|
||||||
private final Map<String, WeakReference<Object>> mObjects = new HashMap<>();
|
private final Map<String, SoftReference<Object>> mObjects = new HashMap<>();
|
||||||
|
|
||||||
void put(String id, Object obj) {
|
void put(String id, Object obj) {
|
||||||
mObjects.put(id, new WeakReference<>(obj));
|
mObjects.put(id, new SoftReference<>(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Object get(String id) {
|
public Object get(String id) {
|
||||||
final WeakReference<Object> weakObj = mObjects.get(id);
|
final SoftReference<Object> softRef = mObjects.get(id);
|
||||||
if (weakObj == null) {
|
if (softRef == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Object obj = weakObj.get();
|
final Object obj = softRef.get();
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
mObjects.remove(id);
|
mObjects.remove(id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user