Skip to content

Commit f2bd0e2

Browse files
committed
Add Class::Singleton
1 parent 50cb278 commit f2bd0e2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

include/jni/class.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ namespace jni
108108
return Class(FindClass(env, TagType::Name()));
109109
}
110110

111+
static const Class& Singleton(JNIEnv& env)
112+
{
113+
// The global references created here is purposefully leaked. Due to the design
114+
// of Java/JNI, there is virtually no way to reliably release them. See
115+
// http://bleaklow.com/2006/02/18/jni_onunload_mostly_useless.html for details.
116+
static Class singleton = Find(env).NewGlobalRef(env).release();
117+
return singleton;
118+
}
119+
111120
template < class... Args >
112121
Constructor<TagType, Args...> GetConstructor(JNIEnv& env) const
113122
{

0 commit comments

Comments
 (0)