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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:57:11+00:00 2026-05-22T17:57:11+00:00

I have an activity that constantly (several times per second) sends byte[] data to

  • 0

I have an activity that constantly (several times per second) sends byte[] data to a service via AIDL. The service forwards these messages using a message–bundle* to a network thread’s handler. The network thread also constantly receives data, which it sends to the service‘s handler as message–bundle. The service sends this bundle to other activities through AIDL.

As you can tell, there is a lot of memory allocated for the bundles.

After viewing my memory allocations on DDMS I see that memory is allocated for:

  • the bundle being initialized
  • the hash map being created
  • the byte[] data I am adding as an entry to the hash table

I would like to reduce memory allocations to as little as possible.

Is there a better way to send byte[ ] across activities/threads than through messages with bundles?

*By message–bundle, I mean a message with a bundle as the data

Tried: to make a pool of bundle objects, but that didn’t work out too well – hard to manage between activities and I don’t know how to pre-allocate it with byte[] data…

  • 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-22T17:57:12+00:00Added an answer on May 22, 2026 at 5:57 pm

    Are those byte arrays that big that you really need to worry about? Without knowing anything of your app, I would guess that the bottleneck in the app you’re describing will be in the network handler, rather than the messaging between the Service and the Activity. Unless you’re leaking the Bundles somewhere, the GC should take care of all unused memory and restore it for your app to reuse.

    If anything, I would try to keep those arrays small enough (to avoid allocating and recycling large amounts of memory at once) and send several small messages instead. That way, the app does not consume the available memory all at once and let the GC do its job with a relaxed schedule (i.e., when the CPU is idle) instead of forcing GC to collect the objects immediately.

    Of course, what is “too big” or “small enough” is something you should test in your own app and measure what (if any) is the gain with one approach or other.

    Update:

    Copying verbatim from an android dev site article:

    In a performance-sensitive code path, such as the layout or drawing method of a view or the logic code of a game, any allocation comes at a price. After too many allocations, the garbage collector will kick in and stop your application to let it free some memory. Most of the time, garbage collections happen fast enough for you not to notice. However, if a collection happens while you are scrolling through a list of items or while you are trying to defeat a foe in a game, you may suddenly see a drop in performance/responsiveness of the application. It’s not unusual for a garbage collection to take 100 to 200 ms. For comparison, a smooth animation needs to draw each frame in 16 to 33 ms. If the animation is suddenly interrupted for 10 frames, you can be certain that your users will notice.

    Based on your comment, I would reconsider whether the GC is relevant in your case. Heap limit may vary between 16 and 32 MB (and the upper limit is probably growing). Assuming 10 allocations per second, 64 bytes per allocation, you would allocate 1 MB every 30 minutes (approx). If the GC takes 200 ms to free that memory, the effect will be negligible. I understand that the numbers here do not consider the memory needed for the hash map nor the bundle, but they are still relevant to give you an idea of the orders of magnitude that we’re talking about. Now, consider how much time does a network request to grab those 64 bytes from the net. Even if it requires just 50 ms, that is 1/4 to 1/2 of the time needed by the GC, every net request. That does not even consider the time required by your Activity to process that data.

    So, in conclusion, before restructuring your code in an attempt to improve its efficiency, make sure that the step you’re modifying is actually a bottleneck, or all your effort might be wasted. Just my $0.02.

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

Sidebar

Related Questions

I currently have a remote service that communicates constantly with an activity on the
I have an activity that contains several user editable items (an EditText field, RatingBar,
I have a web-based application that notifies users of activity on the site via
I Have activity that get some data from the internet, and shows it to
I am a begginer in android,here I have activity that use web service: SoapObject
I have an activity that is a service which plays audio using a media
I have an activity that has a TabHost containing a set of TabSpecs each
I have an activity that launches another activity with startActivityForResult method. I would like
This seems like a simple problem: I have a WF4 activity that guides the
i have created a workflow activity that do give the item creater of a

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.