hi, looking furthur it seems to be a problem with caching the env when the
global ref is created and using the same in destruction (which would not be
same if destruction is on other thread with its own env).  I dont know the
overhead involved in not caching the env.

Thanks,
Zaheer

JObjectWrapper::JObjectWrapper(jobject instance)
    : m_refCount(0)
{
    assert(instance);
// ANDROID
    if (!instance)
        LOGE("Attempted to create JObjectWrapper for null object");
// END ANDROID

    // Cache the JNIEnv used to get the global ref for this java instanace.
    // It'll be used to delete the reference.
    m_env = getJNIEnv();

    m_instance = m_env->NewGlobalRef(instance);

    LOGV("new global ref %p for %p\n", m_instance, instance);

    if (!m_instance)
// ANDROID
        LOGE("%s:  could not get GlobalRef for %p\n", __PRETTY_FUNCTION__,
instance);
// END ANDROID
}

JObjectWrapper::~JObjectWrapper()
{
    LOGV("deleting global ref %p\n", m_instance);
    m_env->DeleteGlobalRef(m_instance);
}


On Thu, Aug 26, 2010 at 10:55 AM, Zaheer <[email protected]> wrote:

> Yes, thats what iam trying to do. The docs that i see suggest the global
> refs can be shared across threads, but i dont seem to find any reference on
> the deletion ownership.
>
> Thanks,
> Zaheer
>
>
> On Thu, Aug 26, 2010 at 7:42 AM, DanH <[email protected]> wrote:
>
>> He's apparently attempting to delete the JNI global ref.
>>
>> My JNI knowledge is pretty sketchy, but I kinda recall that there's
>> some sort of thread ownership of them and you need to transfer
>> ownership before you can delete.
>>
>> On Aug 25, 9:03 pm, TreKing <[email protected]> wrote:
>> > On Wed, Aug 25, 2010 at 8:23 AM, Zaheer <[email protected]> wrote:
>> > > Iam trying to delete objects created in a main java thread from a
>> different
>> > > thread
>> >
>> > What do you mean by "delete" ? This is not something I'd expect to see
>> in a
>> > Java program. Also, posting the code where you're doing this that
>> results in
>> > the crash is probably a good idea.
>> >
>> >
>> -------------------------------------------------------------------------------------------------
>> > TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
>> > transit tracking app for Android-powered devices
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]<android-developers%[email protected]>
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to