• Post Reply Bookmark Topic Watch Topic
  • New Topic

How know ref is local/global? Can I call DeleteGlobalRef on local w/out problem?  RSS feed

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm being passed a jobject that I need to manage the memory of. When i'm done in a function I need to call DeleteLocalRef or DeleteGlobalRef on it depending on which it is. How can i tell this? Can i call either delete without an error (in which case, I'll call both to be sure)?
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I actually researched it a bit, because I didn't know the answer. I came up blank. There doesn't seem to be any (official) way to know. But I don't absolutely know that for sure -- it's just that I can't find a way to do it either.
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
I actually researched it a bit, because I didn't know the answer. I came up blank. There doesn't seem to be any (official) way to know. But I don't absolutely know that for sure -- it's just that I can't find a way to do it either.


Thanks for looking into it!

Seems kind of weird though doesn't it?

In my tests I've been able to call both an both global and local refs without an error, but that's not a guarantee that somewhere down the road a situation won't come up that will blow up because of that call.

I guess I'm going to have to litter my code with a bool and a check of that bool (and careful synchronizing to be sure it's only set if global/local is set, watching for thread access). Seems like a lot of unnec. work for something that should be simple.

EDIT: Looks like it's coming in the next version of Java/JNI.

I guess someone else noticed it was missing.

http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/functions.html

jobjectRefType GetObjectRefType(JNIEnv* env, jobject obj);

The function GetObjectRefType returns one of the following enumerated values defined as a jobjectRefType:

JNIInvalidRefType = 0,
JNILocalRefType = 1,
JNIGlobalRefType = 2,
JNIWeakGlobalRefType = 3


of course, that does me no good since I have to write code that works with the old versions of JNI. I wonder if there's a workaround.
[ May 16, 2008: Message edited by: Dan Bizman ]
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dan Bizman:
(..snip..)I guess I'm going to have to litter my code with a bool and a check of that bool (and careful synchronizing to be sure it's only set if global/local is set, watching for thread access). Seems like a lot of unnec. work for something that should be simple.


That's what I do, ... sounds to me like JSR wording should be revisited.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!