@@ -174,6 +174,7 @@ static uint64_t get_hpy_handle_for_object(HPyContext *ctx, jobject hpyContext, j
174174 (* jniEnv )-> SetIntField (jniEnv , hpyContext , jniField_nextHandle , next_handle + 1 );
175175 }
176176 (* jniEnv )-> SetObjectArrayElement (jniEnv , hpy_handles , next_handle , element );
177+ (* jniEnv )-> DeleteLocalRef (jniEnv , hpy_handles );
177178 /* TODO(fa): update native data pointer cache here (if specified) */
178179 return boxHandle (next_handle );
179180}
@@ -185,6 +186,7 @@ static jobject get_object_for_hpy_handle(jobject hpyContext, uint64_t bits) {
185186 return NULL ;
186187 }
187188 jobject element = (* jniEnv )-> GetObjectArrayElement (jniEnv , (jobjectArray )hpy_handles , (jsize )unboxHandle (bits ));
189+ (* jniEnv )-> DeleteLocalRef (jniEnv , hpy_handles );
188190 if (element == NULL ) {
189191 LOGS ("handle delegate is NULL" )
190192 }
@@ -198,6 +200,7 @@ static jobject get_object_for_hpy_global(jobject hpyContext, uint64_t bits) {
198200 return NULL ;
199201 }
200202 jobject element = (* jniEnv )-> GetObjectArrayElement (jniEnv , (jobjectArray )hpy_globals , (jsize )unboxHandle (bits ));
203+ (* jniEnv )-> DeleteLocalRef (jniEnv , hpy_globals );
201204 if (element == NULL ) {
202205 LOGS ("globals element is NULL" )
203206 return NULL ;
@@ -300,6 +303,7 @@ static HPy ctx_Global_Load_jni(HPyContext *ctx, HPyGlobal global) {
300303 }
301304
302305 uint64_t new_handle = get_hpy_handle_for_object (ctx , hpyContext , element , false);
306+ (* jniEnv )-> DeleteLocalRef (jniEnv , element );
303307 if (new_handle ) {
304308 load_global_native_data_pointer (ctx , bits , new_handle );
305309 return toPtr (new_handle );
0 commit comments