Android Camera Garbage Collection.

by Karan Parikh » Wed, 27 May 2009 03:47:10 GMT


Sponsored Links
 Hey All,
      I am developing a camera application , where the frame rate is
important. However, camera uses a preview callback function which
allocates a byte[] array of 230400 bytes, which makes it necessary for
the garbage collection to step in. Can someone suggest me a way to
avoid garbage collection stepping in ?
Thanks in advance.
Regards,
Karan.


--~--~---------~--~----~------------~-------~--~----~



Android Camera Garbage Collection.

by Robert Green » Wed, 27 May 2009 04:14:14 GMT


 Are you talking about the method Camera.PreviewCallback.onPreviewFrame
(byte[] arg0, anrdoid.hardware.Camera arg1) ?

Is it allocating a new byte[] for every call?

I would think it would keep its same byte[] and reuse it for each
call.

Posting more code may help.  Thanks



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Android Camera Garbage Collection.

by Tom Gibara » Wed, 27 May 2009 04:17:46 GMT


 I'm pretty sure I have looked into this in the past and found that a
different object reference is supplied on each call.
Tom.

2009/5/26 Robert Green <rbgrn....@gmail.com>



--~--~---------~--~----~------------~-------~--~----~



Android Camera Garbage Collection.

by Bo » Wed, 27 May 2009 07:19:13 GMT


 I would like to know that as well. According to the log, garbage
collector is freeing the byte array on every callback. It's a big
waste of time.

Best,

Bo



--~--~---------~--~----~------------~-------~--~----~



Android Camera Garbage Collection.

by karan parikh » Thu, 28 May 2009 13:26:11 GMT


 Hey All,
      @Robert: Yes. I am talking about the same function call. If you read
the documentation for that, It says that a new copy is assigned everytime.
You could also verify it with the allocation tracker. It is assigning that
memory multiple times.
      @Tom: Yes a new object reference is supplied each time.
My suggestions:
1. We could implement a different jar file so that the frame gets
overwritten everytime. But then I believe this would remove the portability
from the application.
2. We can change the garbage collector or play around with the memory
allocation for that very thread. I believe each thread has a generational
gc. We could further look into that. We could overwrite the memory for that
particular allocation each time, rather than freeing it and reallocating the
same.
3. We can ask some one from google to look into it directly and create an
issue, which I will be doing by tonight.
Please let me know your suggestions to remove this bottleneck.
Thanks for commenting.
Regards,
Karan.







-- 
Regards,
-Karan.

--~--~---------~--~----~------------~-------~--~----~



Android Camera Garbage Collection.

by Mike Hearn » Thu, 28 May 2009 22:17:07 GMT


 If you want to distribute the app to existing Android phone owners,
you're out of luck. You'll have to file a bug.

How does the Camera app itself handle this situation?

--~--~---------~--~----~------------~-------~--~----~



Android Camera Garbage Collection.

by Robert Green » Thu, 28 May 2009 23:49:29 GMT


 Have you guys tested it previewing to a surfaceview instead?  I'm
wondering if it doesn't behave differently there.





--~--~---------~--~----~------------~-------~--~----~



Android Camera Garbage Collection.

by Robert Green » Thu, 28 May 2009 23:55:18 GMT


 Karan,

Option 1 is no good - only stubs are in Android.jar for things like
that.  Most of that code is native.  You'd need a custom build of
Android.  If it was just an issue of java, you could write your own
code but since it's native, you're right, portability is the problem.

Option 2 is no good - You can't really change the GC and you can't
really control memory allocation for the thread.  The fact of the
matter is that 284k is being allocated for every frame in native code,
and no amount of messing with stuff is going to change that.

Option 3 works.

Option 4 could be trying alternative ways of getting that data more
efficiently.  I was thinking that running it through a surfaceview and
manipulating its bitmap might work.  It's certainly a hack but it's
worth a shot.





--~--~---------~--~----~------------~-------~--~----~



Android Camera Garbage Collection.

by Bo » Fri, 29 May 2009 06:28:12 GMT


 n May 28, 11:54pm, Robert Green <rbgrn....@gmail.com> wrote:

I don't think this option 4 really works. The surfaceholder must be
set to SURFACE_TYPE_PUSH_BUFFERS to get camera preview. This would
create "a surface that doesn't owns its buffers. With such a surface
lockCanvas will fail."

Best,

Bo

--~--~---------~--~----~------------~-------~--~----~



Android Camera Garbage Collection.

by karan parikh » Fri, 29 May 2009 10:37:17 GMT


 ey,
I have created the issue. It is Issue number 2794. Please look at it
and add extra comments if necessary. I agree with Bo, It is not possible to
do the option number 4. I think there are some changes that are required to
be incorporated in the jar file or provide us with a new API.
Regards,
Karan.

On Thu, May 28, 2009 at 3:27 PM, Bo <wang.b.fr...@gmail.com> wrote:



--
Regards,
-Karan.

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Connect Device to PC through USB

Hi,
       Is it possible to connect to PC through USB from android application.

       Or is it possible by any other way.
       I want to connect to it to transfer data(video)

Regards,
Zeeshan

--~--~---------~--~----~------------~-------~--~----~

2. Limit EditText to alpha-numeric characters

I have been searching through the InputFilter documentation trying to
find a good way to do what I want.

I want to create an edittext that only allows alpha-numeric
characters.  I don't think any of the InputText pre-made filters do
this.  I was looking at creating my own filter using
InputFilter.filter, but the documentation seems a little sparse
explaining the method's parameters and what it is looking for.  This
is probably due to my lack of experience with the topic.

Searching the internet, it does not seem like anyone else is trying to
do this so maybe I am not even going about this the correct way.

Any help would be appreciated.
--~--~---------~--~----~------------~-------~--~----~

3. Unicode

4. Androidster

5. Tambahan Tips mengetik cepat tanpa real Keyboard

6. Dev 1 Phone Update..

7. Trik mengetik Cepat, minimal error di Android Phone