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 DynamicFromMap object pool synchronization #17842

Closed
Closed
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
Expand Up @@ -9,13 +9,18 @@

import javax.annotation.Nullable;

import android.support.v4.util.Pools;
import android.support.v4.util.Pools.SimplePool;

/**
* Implementation of Dynamic wrapping a ReadableMap.
*/
public class DynamicFromMap implements Dynamic {
private static final Pools.SimplePool<DynamicFromMap> sPool = new Pools.SimplePool<>(10);
private static final ThreadLocal<SimplePool<DynamicFromMap>> sPool = new ThreadLocal<SimplePool<DynamicFromMap>>() {
@Override
protected SimplePool<DynamicFromMap> initialValue() {
return new SimplePool<>(10);
}
};

private @Nullable ReadableMap mMap;
private @Nullable String mName;
Expand All @@ -24,7 +29,7 @@ public class DynamicFromMap implements Dynamic {
private DynamicFromMap() {}

public static DynamicFromMap create(ReadableMap map, String name) {
DynamicFromMap dynamic = sPool.acquire();
DynamicFromMap dynamic = sPool.get().acquire();
if (dynamic == null) {
dynamic = new DynamicFromMap();
}
Expand All @@ -37,7 +42,7 @@ public static DynamicFromMap create(ReadableMap map, String name) {
public void recycle() {
mMap = null;
mName = null;
sPool.release(this);
sPool.get().release(this);
}

@Override
Expand Down