Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7963275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:34:28+00:00 2026-06-04T05:34:28+00:00

Global Reference in JNI is said to be a reference that has to be

  • 0

Global Reference in JNI is said to be a reference that has to be manually freed by the programmer. It has nothing to do with the c context. so a code like :

{
    jclass clsStr = (*env)->NewGlobalRef(env,cls); 
}

return clsStr;

will give an error saying that clsStr is undefined / undeclared. I understand this. But what i don’t understand is the use of these type of references.

What is global about clsStr in the above code ? How this variable can be useful in future or after the call returns ? I also read that “Basically, the global reference is useful for ensuring that it (and its contents) will survive to the next JNI invocation” but i don’t understand this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:34:29+00:00Added an answer on June 4, 2026 at 5:34 am

    It means that you’re allowed to hold on to the reference you get from NewGlobalRef() across multiple calls to the native mathod. The reference will remain valid until you explicitly call DeleteGlobalRef().

    This is in contrast to local references:

    A local reference is valid only within the dynamic context of the native method that creates it, and only within that one invocation of the native method. All local references created during the execution of a native method will be freed once the native method returns.

    If you store a global reference in a variable that’s allowed to go out of scope before you call DeleteGlobalRef(), you leak memory. The following is an example of that:

    {
        jclass clsStr = (*env)->NewGlobalRef(env,cls); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a global header and footer that has a Database connection and a
I have code in global.asax that sets some things in cache with CacheItemRemovedCallback. When
I have some JNI code in a thread that calls from Java to C.
I have a 'reference' SQL Server 2005 database that is used as our global
With reference to the following link: http://docs.python.org/faq/library.html#what-kinds-of-global-value-mutation-are-thread-safe I wanted to know if the following:
I'm referring to this Nimbus reference . I tried to set global Font to
Global scope allows you to use a variable in a function that was defined
Is there a way to get around having to reference Global variables inside a
I have a code like this where I am trying to add an event
According to this reference for operator new : Global dynamic storage operator functions are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.