template<typename T>
class facebook::yoga::vanillajni::ScopedGlobalRef< T >
ScopedGlobalRef is a sort of smart reference that allows us to control the lifespan of a JNI global reference.
This class is designed so that when a ScopedGlobalRef goes out of scoped, its destructor will delete -JNIEnv->DeleteGlobalRef()- the underlying JNI reference.
This class should be used to wrap all the global references we create during normal JNI operations if we want reference to eventually go away (in JNI it is a common operation to cache some global references throughout the lifespan of a process, in which case using this class does not really make sense). The idea behind this is that in JNI we should be very explicit about the lifespan of global references. Global references can quickly get out of control if not freed properly, and the developer should always be very aware of the lifespan of each global reference that is created in JNI so that leaks are prevented.
This class is very explicit in its behavior, and it does not allow to perform unexpected conversions or unexpected ownership transfer. In practice, this class acts as a unique pointer where the underlying JNI reference can have one and just one owner. Transferring ownership is allowed but it is an explicit operation (implemented via move semantics and also via explicitly API calls).
Note that this class doesn't receive an explicit JNIEnv at construction time. At destruction time it uses vanillajni::getCurrentEnv() to retrieve the JNIEnv.
It is OK to cache a ScopedGlobalRef between different JNI native method calls.