how to release memory

  ... discussions about development with the GLES1 branch of AndEngine.

how to release memory

Postby xmxkkk » Wed Feb 01, 2012 10:30 am

i use one BaseExample and more scene .
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. getEngine().clearUpdateHandlers();
  2. getEngine().getScene().clearChildScene();
  3. getEngine().getScene().clearEntityModifiers();
  4. getEngine().getScene().clearTouchAreas();
  5. getEngine().getScene().clearUpdateHandlers();
  6. getEngine().getFontManager().clear();
  7. getEngine().getTextureManager().clear();
  8. System.gc();
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

the methods can't release memory ,lead to memory leak. it's very Serious.
Each time add 6000 Objects ,release 500 Objects.
when objects reach to 111000, it's Crash.

help and sos.

Solved:
i use Memory Analyzer 1.1.1 tools to see HPROF file , then i find the BufferObjectManager class is so big and big.
so i called BufferObjectManager.getActiveInstance().clear(); method ,it's work and very useful .
because i use andengine's source , so i change something.
this's my method.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. BufferObjectManager.getActiveInstance().clear();
  2. getEngine().getTextureManager().clear();
  3.  
  4. getEngine().clearUpdateHandlers();
  5. getEngine().getScene().clearChildScene();
  6. getEngine().getScene().clearEntityModifiers();
  7. getEngine().getScene().clearTouchAreas();
  8. getEngine().getScene().clearUpdateHandlers();
  9. getEngine().getFontManager().clear();
  10. System.gc();
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

Sorry,bad English.
:lol: :lol: :lol: :lol: :lol:
Last edited by xmxkkk on Wed Feb 01, 2012 2:23 pm, edited 8 times in total.
xmxkkk
 
Posts: 3
Joined: Fri Jun 17, 2011 10:57 am

Re: how to release memory? guys ,help and sos.

Postby ViktorS » Wed Feb 01, 2012 10:40 am

As far as I know Java doesn't have a way to fully release memory. Even if you set everything to null you will still have to wait for garbage collector, what's more Android doesn't really let you release resources also, even after your application closes it holds some parts of your application to itself. Also, all STATIC content isn't really relesed, so use static modifier less.
'Javelin OU' presents, my latest game - Joj the alien
ViktorS
 
Posts: 580
Joined: Thu Oct 27, 2011 2:18 pm

Re: how to release memory? guys ,help and sos.

Postby Fofole » Wed Feb 01, 2012 11:00 am

I was right about to put in kinda of a similar question. I use object pool for my AnimatedSprites and after I finish my activity the object pool continues to create objects. So after a few times I play the game it will crash. I think this problem is similar(ish) to what you described? I get objectPool was exhausted with K objects not recycled yet, allocated 1 more. And then K keeps incrementing to outrageous numbers until the app crashes.
Fofole
 
Posts: 48
Joined: Thu Jan 26, 2012 1:30 pm

Re: how to release memory? guys ,help and sos.

Postby ViktorS » Wed Feb 01, 2012 11:26 am

well I'll suggest something that MIGHT help, not sure it will though...
1) Use this code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.         public final void onPause() {
  3.                 if (this.isFinishing()) {
  4.                         // Manual release of your resources.
  5.                 }
  6.                 super.onPause();
  7.         }
  8.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

I use this piece of code for several things, one of which is: Setting everything with static modifier to null;
Not sure it really helps, just read somwhere that it shuld help...

2) Use this to unload textures manually through out application:
mEngine.getTextureManager().unloadTexture(mTexture);

I usually have a method that accepts Texture[] Array as a parameter and goes through it unloading textures. I ususally do that when switching scenes.
'Javelin OU' presents, my latest game - Joj the alien
ViktorS
 
Posts: 580
Joined: Thu Oct 27, 2011 2:18 pm


Return to GLES1

Who is online

Users browsing this forum: Google Feedfetcher and 10 guests