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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:22:58+00:00 2026-06-11T12:22:58+00:00

I am experiencing a very strange phenomenon (test device: HTC Desire HD, Android 2.3.5).

  • 0

I am experiencing a very strange phenomenon (test device: HTC Desire HD, Android 2.3.5). I know that System.gc() is needless and discouraged, and I don’t try to suggest otherwise, but the point is that it shouldn’t cause issues either (i.e. it should be useless at most).

I have an application which contains a GLSurfaceView in its view hierarchy. The GLSurfaceView is instantiated and added in the Activity.onCreate(). Normally, the application works like this:

  1. User starts the app and goes to mainmenu
  2. User chooses a mainmenu item which sets the GLSurfaceView to View.VISIBLE
  3. User plays with the in-built game on GLSurfaceView
  4. User goes to mainmenu and exits the activity (=> Activity.finish() is called)

My Activity.onPause() looks like this:

mGameThread.pause(); // gameThread is my custom thread class for the in-built game
mGLView.onPause(); // pause the renderer thread

So far so good, everything works fine. However, issues appear after I add the following code to onPause() (for the case when the user exits the game from the mainmenu):

mGameThread.pause(); // gameThread is my custom thread class for the in-built game
mGLView.onPause(); // pause the renderer thread    
if (isFinishing()) {
    System.gc();
}

In details: if the Activity is started for the first time (= i.e. the app process didn’t exist before), everything works fine. However, starting from the 2nd start of the activity (= after the first exit from the mainmenu, i.e. after the first Activity.finish()), the framerate of GLSurfaceView is reduced by 40-50%, the in-built game becomes slow.

If I remove the System.gc() call, the problem disappears. Moreover, if I do the following, it also gets rid of the problem:

mGameThread.pause(); // gameThread is my custom thread class for the in-built game
mGLView.onPause(); // pause the renderer thread
if (isFinishing()) {
    // 1. get layout root of View hierarchy

    // 2. recursively remove (detach) all Views

    // 3. call GC
    System.gc();
}

I didn’t add concrete code because it’s complex, so I used comments. If I just detach the GLSurfaceView via removeView(), it is not enough. The entire view hierarchy needs to be cleared.

Note that I couldn’t find any memory leaks (no Activity leak via drawables/statics etc.). Moreover, of course, the gameThread properly exits when the app is closed (I just didn’t include its source code).

Any ideas, guesses? Apparently, System.gc() seems to cause some issues for the Activity/layout destroying mechanism of Android. Again, as I said, if I remove System.gc(), the problem disappears.

  • 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-06-11T12:23:00+00:00Added an answer on June 11, 2026 at 12:23 pm

    I have experience of Android Game Programming. I used to clear all the view in hierarchy because when running threads if you call System.gc() sometimes it happens that your thread has a reference to some of your view, even if you call system.gc() this view won’t get removed and if you keep playing again and again this game you will notice that your heap memory is started growing.

    It depends upon the memory leak, if you are leaking some KB memory it will take more time to crash your game. The best way it to use Eclipse Memory Anlyser (Eclipse MAT) and compare your stacks.

    Step1:
    take memory snap shot when you start your game for first time
    Step2:
    take memory snap shot when you start your game second time
    Step3:
    Now compare your both stacks of snapshots it will tell you the difference.

    It is a very useful tool. I was having huge memory issues in my game Apache Attack. I fixed them using this awesome tool.
    Follow this ECLIPSE MAT TUTORIAL

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

Sidebar

Related Questions

I'm experiencing a very strange problem... The following trivial test code works as it
I am experiencing a very strange behaviour of redgate that prevents me from commiting
Good-day, I'm experiencing a very strange event that just started happening. Whenever I press
I am experiencing some very strange behavior with Blend: Since weeks i am working
Hey guys, I'm currently experiencing a very strange crash in Windows 7 in a
I am experiencing a very strange issue. I have developped an application locally and
I'm experiencing a very strange problem... I have a regular ASP.Net webpage with a
I'm experiencing a very strange issue: I use the NUnit framework for testing in
I'm experiencing what I think is a very strange issue. First and foremost, my
I am experiencing a strange behavior with very basic web service development. This question

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.