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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:27:31+00:00 2026-05-28T06:27:31+00:00

I’ve got an app where a thread is trying to send lots of Location

  • 0

I’ve got an app where a thread is trying to send lots of Location objects via a Handler to the UI thread, where they get analyzed and passed on to other threads. I’ve noticed the app has a memory leak, as it eventually crashes 2-3 hours after starting up. If I use DDMS to profile the heap, I notice a gradual increase in the number of “Data Objects” (about 1500 per minute). It appears those 1500 are approximately evenly split between 16-byte and 32-byte items.

After gradually disabling parts of my app, I found that the Location generating thread’s call to the Handler appears to cause the leak.

I have gradually narrowed down the required parts of my thread to this:

class UIActivity implements Handler.Callback
{
@Override 
public void onCreate()
{
  m_handler = new Handler(this);
}

@Override
public boolean handleMessage(Message m)
{
  switch(m.what)
  { 
    case FAKE_LOCATION:
      m.obj = null; // desperate anti-leak measures
      return true;
  }
  return false;
}
public static class FakeLocationGenerator extends Thread
{
  private Handler m_callback;
  public FakeLocationGenerator(Handler callback)
  {
    m_callback = callback;
    start();
  }

  @Override
  public void run()
  {
    while(true)
    {
      Thread.sleep(50); // makes for 20hz
      Location l = new Location("fake");
      Message m = new Message();
      m.what = FAKE_LOCATION;
      m.obj = l;
      m_callback.SendMessage(m);
    }
  }
}
}

The Handler.Callback.handleMessage() implementation on the UI activity just returns true and does nothing with the message. If I comment out the m_callback.SendMessage call, then the memory leak disappears. I tried a giant hack of calling Handler.removeMessages(FAKE_LOCATION) after each FAKE_LOCATION message, but that did nothing.

Any ideas?

  • 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-28T06:27:32+00:00Added an answer on May 28, 2026 at 6:27 am

    Firstly, you should be using Message.obtain() and Message.recycle().

    Secondly, is it possible that maybe there is no leak and you are simply generating new messages faster than they are being processed…?

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

Sidebar

Related Questions

I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to select an H1 element which is the second-child in its group

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.