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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:30:53+00:00 2026-05-20T06:30:53+00:00

I have written a mapping application which can either use Google Maps or Open

  • 0

I have written a mapping application which can either use Google Maps or Open Street Map
as a tile provider. The Google and OSM maps are displayed in separate activities. After the
splash screen a select mode activity is entered. From this screen the user can either
choose the Google or OSM activty via a button.

I’d like to be able to switch between Google and OSM via a button in each mapping activity. When I code the click handler for each of the mapping activities, I have in each:

i = new Intent("com.me.otheractivity");
finish();
startActivity(i);

I have no service connection, or inner classes for overlays etc. anywhere in the code.
When I traverse from Select->Google-> Select(via back button) -> OSM , all is fine in terms
of allocated heap.

If I go directly from one mapping activity to the other repeatedly, then the allocated heap
grows and eventually crashes at 16M. Obviously it must be leaking somewhere via this route.

I’m logging every onCreate, Start, Resume, Pause, Stop and Destroy in all 3 activities.
If I use the back button route I have the log:

Select Activity -> Google Activity -> OSM Activity (direct via button in Google Activity)

Select Activity Pause 
Google Activity Create
Google Activity Start 
Google Activity Resume
Select Activity Stop 
Google Activity Pause 
Open SM Activity Create 
Open SM Activity Start 
Open SM Activity Resume 
Google Activity Stop 
Google Activity Destroy

Going via back button, I get

Select Activity -> Google Activity -> Select Activity -> OSM (via back button)

Select Activity Pause 
Google Activity Create 
Google Activity Start
Google Activity Resume 
Select Activity Stop
Google Activity Pause 
Select Activity Start 
Select Activity Resume 
Google Activity Stop 
Google Activity Destroy
Select Activity Pause
Open SM Activity Create
Open SM Activity Start
Open SM Activity Resume
Select Activity Stop 

In the first example the Google Activity is not stopped or destroyed until after the OSM
one is created, started and resumed. Is this significant regarding the leak?

I set to null all timers, handlers and overlays in the onPauses. (Combining the two views in one activity is not really an option owing to the differences between the Google maps.jar and osmdroid.jar)

Is anything wrong with the code in my click handlers?

All suggestions will be gratefully received.

EDIT 26th Feb

Further to my original post – the salient point for me is :

Why is it necessary for the onDestroy in one activity to run before the onResume in the second activity for the memory usage to stop growing?

If the onResume in activity B runs before the onDestroy in activity A, then I see that the number of activities on the history stack (as reported by adb shell dumpsys meminfo) increase by one each time. No amount of forced GC either in the code or via DDMS will take them off the stack.

I’ve since modified my code so that the clickhandler just calls finish(). In the onDestroy I call the startActivity(). This briefly returns the screen to the select mode activity before running the other activity. Under these circumstances obviously the onDestroy() in A runs before the onResume() in B and neither the history stack or heap usage grow.

I just don’t get it.

  • 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-20T06:30:53+00:00Added an answer on May 20, 2026 at 6:30 am

    I would heavily recommend using the Eclipse MAT (Memory analyzer) tool against all android apps you plan to release.

    I have noticed apps I have worked on ending up with memory leaks from patterns a standard java developer knows would not create a memory leak.

    Use the MAT tool to trace the dependencies causing leaks and either rework that code or in worst case scenarios I have resorted to reflection to break the dependency and allow it to release.

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

Sidebar

Related Questions

I have written a piece of code in python, in which I am asking
i have written an iphone application but when i run it only blank screen
I have written a server and a client both as separate apps. They communicate
I have written a linux daemon that will be (and must be) running as
I have written a program in C# using Visual Studio 2010. At current it
I have written a ListActivity class that uses a custom ArrayAdapter and Holders. I
I have written REST web service in netbean IDE using jersey framework and java.
I have written the following code in MATLAB to process large images of the
I have written a logic where by default if anyone wants to clear the
I have written a code in Python to create a transition probability matrix from

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.