Release Byte Array

1,449 views
Skip to first unread message

B.Arunkumar

unread,
Mar 2, 2012, 1:14:31 AM3/2/12
to android-ndk
Hi,

I have a jbyteArray which is created and assigned the values of
jbyte* array. How do I release the jbytearray from memory?

jbyteArray trial;
jbyte* data;

jbyteArray Java_com_example_Test_Client_tobytearray(JNIEnv * env,
jobject thiz)
{
int size=len;

trial = env->NewByteArray(size);

data = (jbyte*)decodeframe;
env->SetByteArrayRegion(trial,0,size,data);

return trial;
}

Thank you,
B.Arunkumar

Mārtiņš Možeiko

unread,
Mar 2, 2012, 1:43:52 AM3/2/12
to andro...@googlegroups.com
Don't worry about that - Java uses garbage collection to automatically
free objects that are not used anymore.

--
Mārtiņš Možeiko

> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>

B.Arunkumar

unread,
Mar 2, 2012, 3:21:22 AM3/2/12
to android-ndk
Hi,

Thank you for your reply. The byte array we get is converted into a
Bitmap in Android and rendered on ImageView (The entire app is about
rendering H.264 Video from IP Caamera on Android mobile). Sometimes we
are running into memory leaks. I am not sure if this is the right
forum to ask this question but sometimes we get this message in the
logcat on the OnDestory of Activity class:

E/WindowManager( 9859): Activity
com.example.OnVRViewer.AsyncRecordTrial has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView@405aeeb8 that
was originally added here

E/WindowManager( 9859): android.view.WindowLeaked: Activity
com.example.OnVRViewer.AsyncRecordTrial has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView@405aeeb8 that
was originally added here

E/WindowManager( 9859): at android.view.ViewRoot.<init>(ViewRoot.java:
266)

E/WindowManager( 9859): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:174)

E/WindowManager( 9859): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:117)

E/WindowManager( 9859): at android.view.Window
$LocalWindowManager.addView(Window.java:424)

E/WindowManager( 9859): at android.app.Dialog.show(Dialog.java:241)

E/WindowManager( 9859): at android.app.AlertDialog
$Builder.show(AlertDialog.java:802)

E/WindowManager( 9859): at com.example.OnVRViewer.AsyncRecordTrial
$7.handleMessage(AsyncRecordTrial.java:1581)

E/WindowManager( 9859): at
android.os.Handler.dispatchMessage(Handler.java:99)

E/WindowManager( 9859): at android.os.Looper.loop(Looper.java:123)

E/WindowManager( 9859): at
android.app.ActivityThread.main(ActivityThread.java:3691)

E/WindowManager( 9859): at
java.lang.reflect.Method.invokeNative(Native Method)

E/WindowManager( 9859): at
java.lang.reflect.Method.invoke(Method.java:507)

E/WindowManager( 9859): at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:847)

E/WindowManager( 9859): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)

E/WindowManager( 9859): at dalvik.system.NativeStart.main(Native
Method)

This error appears once in 30 times on testing and sometimes results
in a crash (the alert dialog is dismissed and it appears this is not
the error and is due to some other problem).

My question is this byte array coversion could be the problem?
sometimes not properly GC'ed or something of that sort??

Thank you,
B.Arunkumar

On Mar 2, 11:43 am, Mārtiņš Možeiko <martins.moze...@gmail.com> wrote:
> Don't worry about that - Java uses garbage collection to automatically
> free objects that are not used anymore.
>
> --
> Mārtiņš Možeiko
>
> On Fri, Mar 2, 2012 at 8:14 AM, B.Arunkumar
>

gadget

unread,
Mar 2, 2012, 10:48:44 AM3/2/12
to android-ndk
no, i don't think the byteArray is the problem here.
My guess is one of the following:

1. You're creating ANativeWindow, but then not releasing it
2. You're hanging on to a View objects due to callbacks/other
references
see: http://www.curious-creature.org/2008/12/18/avoid-memory-leaks-on-android/
3. (Possibly) Creating new Views faster than they are destroyed (do
you do new View() in onStart?)

Hope this helps

On Mar 2, 12:21 am, "B.Arunkumar" <awsnetworkrecor...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages