Package glide.managers
Class JniResponseRegistry
- java.lang.Object
-
- glide.managers.JniResponseRegistry
-
public class JniResponseRegistry extends java.lang.ObjectRegistry for storing Java objects returned from JNI calls. This allows us to pass object IDs through the Response protobuf instead of trying to pass Rust pointers that would become invalid.Objects are stored temporarily and must be retrieved via
retrieveAndRemove(long)or cleaned up viaremove(long)to prevent memory leaks. The registry includes monitoring to detect potential leaks by periodically checking registry size.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclear()Clear all stored objects.static booleanremove(long id)Remove an object from the registry without returning it.static java.lang.ObjectretrieveAndRemove(long id)Retrieve and remove a Java object by its ID.static intsize()Get the current number of stored objects.static longstoreObject(java.lang.Object object)Store a Java object and return its ID.
-
-
-
Method Detail
-
storeObject
public static long storeObject(java.lang.Object object)
Store a Java object and return its ID. This is used when JNI returns a converted Java object that needs to be passed through the Response protobuf.IMPORTANT: The caller is responsible for ensuring the object is eventually removed via
retrieveAndRemove(long)orremove(long). Failure to do so will cause memory leaks.- Parameters:
object- The Java object to store- Returns:
- The ID that can be used to retrieve the object, or 0L if object is null
-
retrieveAndRemove
public static java.lang.Object retrieveAndRemove(long id)
Retrieve and remove a Java object by its ID. This is called from valueFromPointer to get the actual Java object. The object is removed after retrieval to prevent memory leaks.- Parameters:
id- The ID of the object to retrieve- Returns:
- The Java object, or null if not found or id is 0
-
remove
public static boolean remove(long id)
Remove an object from the registry without returning it. This is used for cleanup when an exception occurs after storing an object but before it can be retrieved normally.- Parameters:
id- The ID of the object to remove- Returns:
- true if an object was removed, false if no object existed with that ID
-
clear
public static void clear()
Clear all stored objects. Called during client cleanup.
-
size
public static int size()
Get the current number of stored objects. Useful for debugging, monitoring, and detecting potential memory leaks.- Returns:
- The number of objects currently stored in the registry
-
-