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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:53:40+00:00 2026-05-23T03:53:40+00:00

I am working on an app having a lot of image and using a

  • 0

I am working on an app having a lot of image and using a sensor listener that I register at the beginning of the activity with the sensor manager to detect shake events and change images based on shake direction.

I read the event values in onSensorChanged(SensorEvent event) in order to use it in my app:

public void onSensorChanged(SensorEvent event){
     accX = event.values[0];
     accY = event.values[1];
     accY = event.values[2];
 }

I unregister the sensor listener on pause of the activity and also call system.gc for garbage collection.

Everything works well till I am on a single activity.

When I finish current activity and open another activity (again having a a sensor listener), app starts giving out of memory exception after a while:

“OutOfMemoryException: bitmap size
exceeds VM budget”

Note that heap size of the app is never more than 4 MB.

One more observation is that the app never crashes if sensor listener is not used which makes me thinks that possibly there are memory leaks when sensor events are generated and when a new activity is loaded, due to lesser memory available, the app gives OutOfMemoryException when bitmaps are used in the activity.

So seemingly two possible reasons:

  1. images are not recycled properly
    http://code.google.com/p/android/issues/detail?id=8488
  2. every time there is a SensorEvent, somewhere there are memory leaks which decreases the available memory for an app
    Android: reading accelerometer without memory allocation?

I’m also using the solution described in comment 51 here:
http://code.google.com/p/android/issues/detail?id=8488

to recycle everything but it still gives memory issues.

If you can tell me the best approach to use the images in a large size app, how to recycle them and confirm if there are really any memory leaks while using the sensor listener, or any suggestions what I should look for in the app, it will be really helpful.

  • 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-23T03:53:40+00:00Added an answer on May 23, 2026 at 3:53 am

    For the images to get recycled properly, if possible, try using Bitmap.recycle() method. This is becasue the image is actually kept as a reference (in pre-Honeycomb) and the actual data is allocated using native memory.

    In Honeycomb the memory for images is allocated on the heap so it is easilly GCed. Additionally, you may set largeHeap=”true” (again post-Honeycomb).

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

Sidebar

Related Questions

I am having a lot of trouble in working with streams using monodroid. What
I'm having an unexplainable issue with my Rails app. I'm using a lot of
I am working on an app where i am having some linkbuttons in master
I'm working on an app to post music to the Facebook timeline, but having
I am working on learning in-app billing but I am having a problem with
I am working on an iphone app in objective-c and I am having trouble
I am having some threading issues with a large app I am working on
I am working on my first Objective-C app for iOS and am having an
I am working on an android app, and I am having difficulties with ListActivity
I'm working on a OCR Android App, but I'm having lots of problems with

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.