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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:42:42+00:00 2026-06-17T04:42:42+00:00

With JNI, I’m creating a weak global ref from a jobject. And later, when

  • 0

With JNI, I’m creating a weak global ref from a jobject. And later, when trying to access this reference, the dalvik vm crashes on Android 2.3 but not on 4.1 and 4.2. What I found out was that IsSameObject with the object itself and the created weak reference as parameters returns 1 on the working devices and 0 on the devices where it crashes. Does that make sense? Changing to GlobalRef and IsSameObject returns 1.

Here I’m testing IsSameObject right after creating the weak global reference.

this->jMyObject = getEnv()->NewWeakGlobalRef(jMyObject);
LOGV("Is same object = %d", getEnv()->IsSameObject(jMyObject, this->jMyObject));

LOGV is my macro for printing to logcat.

The crash log isn’t very helpful to me:

01-09 09:57:04.778: I/DEBUG(13012): Build fingerprint: 'google/passion/passion:2.3.7/GWK74/121341:user/release-keys'
01-09 09:57:04.778: I/DEBUG(13012): pid: 15001, tid: 15001  >>> org.example.myproject <<<
01-09 09:57:04.778: I/DEBUG(13012): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr de5d8e6f
01-09 09:57:04.778: I/DEBUG(13012):  r0 0018fed8  r1 00000007  r2 de5d8e6f  r3 00000002
01-09 09:57:04.778: I/DEBUG(13012):  r4 437d45d4  r5 431ecda8  r6 beb54098  r7 000010f8
01-09 09:57:04.778: I/DEBUG(13012):  r8 aca12000  r9 0000000c  10 431ecd94  fp aca9f368
01-09 09:57:04.778: I/DEBUG(13012):  ip 000000f8  sp beb54048  lr aca15e2c  pc aca15e18  cpsr a0000010
01-09 09:57:04.778: I/DEBUG(13012):  d0  0065007200670067  d1  006e006900730000
01-09 09:57:04.778: I/DEBUG(13012):  d2  275449202121213a  d3  4546455220412000
01-09 09:57:04.778: I/DEBUG(13012):  d4  8000000000000000  d5  429800003f800000
01-09 09:57:04.778: I/DEBUG(13012):  d6  00000000c2980000  d7  4110000042500000
01-09 09:57:04.778: I/DEBUG(13012):  d8  0000000043eb0000  d9  c35c0000439ce2e0
01-09 09:57:04.778: I/DEBUG(13012):  d10 433d5140405277a8  d11 0000000042354500
01-09 09:57:04.778: I/DEBUG(13012):  d12 0000000000000000  d13 0000000000000000
01-09 09:57:04.778: I/DEBUG(13012):  d14 0000000000000000  d15 0000000000000000
01-09 09:57:04.778: I/DEBUG(13012):  d16 000000000065dea0  d17 c053000000000000
01-09 09:57:04.778: I/DEBUG(13012):  d18 0000000000000000  d19 0000000000000000
01-09 09:57:04.778: I/DEBUG(13012):  d20 3ff0000000000000  d21 8000000000000000
01-09 09:57:04.778: I/DEBUG(13012):  d22 0000000000000000  d23 0000000000000000
01-09 09:57:04.778: I/DEBUG(13012):  d24 0000000000000000  d25 407c000000000000
01-09 09:57:04.778: I/DEBUG(13012):  d26 4030000000000000  d27 3ff0000000000000
01-09 09:57:04.778: I/DEBUG(13012):  d28 0100010001000100  d29 3ff0000000000000
01-09 09:57:04.778: I/DEBUG(13012):  d30 0000000000000000  d31 3ff0000000000000
01-09 09:57:04.778: I/DEBUG(13012):  scr 20000010
01-09 09:57:04.828: I/DEBUG(13012):          #00  pc 00015e18  /system/lib/libdvm.so
01-09 09:57:04.828: I/DEBUG(13012):          #01  pc 0001c0e4  /system/lib/libdvm.so
01-09 09:57:04.828: I/DEBUG(13012):          #02  pc 0001afdc  /system/lib/libdvm.so
01-09 09:57:04.828: I/DEBUG(13012):          #03  pc 00059c40  /system/lib/libdvm.so
01-09 09:57:04.828: I/DEBUG(13012):          #04  pc 00046666  /system/lib/libdvm.so
01-09 09:57:04.828: I/DEBUG(13012):          #05  pc 001b0d3e  /data/data/org.example/lib/libmyproject.so
01-09 09:57:04.828: I/DEBUG(13012):          #06  pc 001b4c7e  /data/data/org.example/lib/libmyproject.so

Do I need to extract the object from the reference? Or should I just avoid weak references altogether?

  • 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-17T04:42:44+00:00Added an answer on June 17, 2026 at 4:42 am

    If I put the weak reference in a NewLocalRef it seems to be doing fine.
    So I ended up with:

    jobject jMyObject = getEnv()->NewLocalRef(jMyWeakObject);
    if(!getEnv()->IsSameObject(jMyObject, NULL)) {
        // do stuff with object
    }
    

    And the member variable is now jMyWeakObject.

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

Sidebar

Related Questions

Hi while trying out jni example in this link http://wendro.blogspot.com/2010/03/jni-example-eclipse-dev-cpp.html?showComment=1309930446765#c5048550711511727724 with eclipse Helios windows
JNI tutorials, for instance this one, cover quite well how to access primitive fields
I am trying to compile a JNI library which uses carbon from the command
I am trying to create a JNI wrapper for this windows application called 'Personal
JNI: How can i check if jobject is a null object in native c
I am using JNI to call my C++ function from Java. One of the
I have a JNI method to access java method which returns an Integer object.
Possible Duplicate: Passing string from Java into JNI passing string array from java to
My java app uses JNI to invoke a library written in C. This native
I have some JNI code in a thread that calls from Java to C.

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.