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 6337189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:12:20+00:00 2026-05-24T19:12:20+00:00

I don’t have much knowledge about JNI and how things are handled inside JNI

  • 0

I don’t have much knowledge about JNI and how things are handled inside JNI environment. I have a simple question.

I have a method in in Java which calls a JNI method and passes a String in parameter . JNI method accepts that string in a jstring object and stores it in a static vector<jstring>.

My question: Is this safe to use this vector throughout the life cycle of java application? Do I need to consider the fact the GC may move String in Java environment? Will that cause any problem in this situation? if yes, what should be the right way?

  • 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-05-24T19:12:20+00:00Added an answer on May 24, 2026 at 7:12 pm

    It may or may not be ok, basically the VM gives you very little promises on what happens to the memory used by jstrings after the JNI call

    Pretty much straight from the source:
    http://java.sun.com/docs/books/jni/html/objtypes.html

    The JNI passes objects to native methods as opaque references. Opaque references are C pointer types that refer to internal data structures in the Java virtual machine. The exact layout of the internal data structures, however, is hidden from the programmer. The native code must manipulate the underlying objects via the appropriate JNI functions, which are available through the JNIEnv interface pointer. For example, the corresponding JNI type for java.lang.String is jstring. The exact value of a jstring reference is irrelevant to the native code. The native code calls JNI functions such as GetStringUTFChars (§3.2.1) to access the contents of a string.

    So long story short, you shouldnt be accessing the value of the jstring directly anyhow, so there is no reason to store the jstrings, use the appropriate methods to convert them to native strings and store them that way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't let below code scare you away . The question is really simple, only
Don't have much to say, just can get into the event handler. XAML: <Grid>
I don't have much PHP experience and I want to know how to best
Don't know much about encryption... Say I'm preparing a SAML request to submit to
Don't freak out about the length of my post, it's pretty simple, I just
Don't think my virtualhost is working correctly. This is what I have inside of
Don't you hate it when you have class Foobar { public: Something& getSomething(int index)
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
I don't understand where the extra bits are coming from in this article about
I have just tried to save a simple *.rtf file with some websites and

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.