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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:28:17+00:00 2026-06-01T06:28:17+00:00

I am writing a somewhat complex game engine in Android. Currently I have a

  • 0

I am writing a somewhat complex game engine in Android.

Currently I have a thread used to update subsystems.

Inside the update method is the method to update game logic, which is based on current game state.

The game state has a scene, which is updated. Scenes are composed of a root node, which makes a simple scene graph structure.

Roots are nodes which have children that are also updated and so on and so forth.

Anyway, this is all nice and dandy and works great, until I get a million of these in my Logcat: 03-29 09:23:22.866: D/dalvikvm(18554): GC_CONCURRENT freed 511K, 52% free 2773K/5767K, external 77K/587K, paused 2ms+3ms

I’ve isolated the cause of the leak to be the update loop, as when I comment out my method to update subsystems, there is no GC messages. Further more, I’ve commented deep into the update loop, and up to the point where the root node’s children update is the point when the GC would run frantically.

(GameLgoic)
public void onUpdate(float deltaTime) 
    {
        if (gameState != null)
            gameState.onUpdate(deltaTime);
    }
(GameState)
public void onUpdate(float deltaTime) 
    {
        scene.onUpdate(deltaTime);
    }
(Scene) 
public void onUpdate(float deltaTime)
    {
        root.onUpdate(deltaTime);
    }
(SceneNode)
public void onUpdate(float deltaTime)
    {
        for (int i = 0; i < children.size(); ++i)
        {
            children.get(i).onUpdate(deltaTime); // Memory leak runs crazily here
        }
    }

If I comment out children.get(i).onUpdate(deltaTime) There is no leaks! My mind is so boggled. Thanks guys.

  • 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-01T06:28:19+00:00Added an answer on June 1, 2026 at 6:28 am

    I ran into similar problem when I made a game for Android. The only way to get out of this is to code embedded-C-Style.
    So if you want a loop, reuse your counting variable, as well as your bounding variable, whenever possible, like so:

    int i;
    int max
    void loop(){
        max = bla.size();
        for(i=0; i<max; i++){ ... }
    }
    

    The same goes for literally everything else you touch. So you might consider to keep references to objects you don’t need anymore and to recycle them later.

    It is insane what difference it made to my game implementing those changes. Framerate doubled, vast reduction of lags and so on.

    You should look into the DDMS tool, which is delieverd which the eclipse Android SDK. You can use it to track down allocations, to avoid those problems.

    Addtionally, you should consider removing all interators, since they are allocated everytime you jump into a loop and cannot be recycled. So it is better to loop manually and to walk through your lists multiple times (get(x) in loop) than having to wait for the garbage collector in the long run.

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

Sidebar

Related Questions

I'm currently writing a Rails app, and hit a somewhat strange quirk. I have
I'm writing a query, and have used the solution in this thread and it
I'm writing a very simple text editor and have run into a somewhat minor
What tips/suggestions do you have for writing more understandable code? I've been somewhat frustrated
This may sound somewhat stupid, but I have to know as I'm writing a
I am currently writing a ContentManager in ASP.NET. I have a preview button which
I have a somewhat special use case, where I'd like to create a method
I am writing somewhat of a proxy program in Java. Here's how it works:
While writing some views to respond to ajax requests i find it somewhat strange
I'm writing a Connect4 game with an AI opponent using adversarial search techniques and

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.