Open GoogleCodeExporter opened 8 years ago
[deleted comment]
Hi, Thanks for reply.
No its not like issue 77.
Let me explain what I am using in my game.
1) GameLayer:
I have taken array of sprites as member variable(to get access during gameplay)
to this CCLayer class and did addChild all this sprites. There are many
animations added to some sprites too.
2) extraGameLayer: This CCLayer I used to addChild to GameLayer at some
particular time as they are diff play as popup game. This also have member
spritearray and animations too.
3) I add this extraGameLayer to and from GameLayer manytime depending on
situation.
Initially it works fine but after playing for 20-25 mins it starts lagging. At
some point it freezes and crash which will cause restart of device. I am using
Samsung Pop, Ace, Galaxy devices to test.
In Log its showing unable to allocate memory. So somewhere memory is leaking.
Please can you advice some tips to avoid this?
Thank you.
Original comment by rajnimge...@gmail.com
on 17 Jun 2011 at 5:17
Possible cause:
Are you frequently creating/destroying other Sprites/Nodes to
GameLayer/extraGamelayer?
I noticed that CCNode.cleanup() doesn't seem to be overridden in CCSprite ( and
CCLabel, etc) so the texture is never released as in issue 83:
http://code.google.com/p/cocos2d-android-1/issues/detail?id=83
Original comment by wopstic...@gmail.com
on 28 Jun 2011 at 6:09
Hi,
Thanks for this information.
Yes you are right, I am doing addChild, removeChild, many CCSprites and
CCLabels as my level changes.
Each lavel contains many sublevels which also having same addChild and
removeChild calls to their member CCSprites and CCLabels.
Can you provide me any fix or help how to overcome this or to use anyother
techniques as as of now its leaking memory if we play continuously.
One thing I did is to load all sprites onetime at starting of game and never
remove them but it takes lots of redundant code and uses more memory allocated
as all images are loaded even if they are not needed.
Thanks.
Original comment by rajnimge...@gmail.com
on 29 Jun 2011 at 4:50
I tried this myself... i.e. creating and removing 4 large sprites every frame,
but the garbage collector handled it perfectly - after 15 minutes I gave up.
Are you adding lots of *different* sprites? i.e. multiple sprite sheets or
files for background/ground/sky sections for each level?
Here's the code I thought about patching into CCSprite, but if you have say 5
happyface sprites on screen, and call removechild(happyFace[0], true); with
the code, it releases the texture for all happyfaces, even if they don't come
from
the same sprite sheet. The others are just drawn as blank white squares since
the texture is loaded only once, but drawn many times.
@Override
public void cleanup() {
super.cleanup();
if ( texture_ != null && CCDirector.gl != null) texture_.releaseTexture(CCDirector.gl);
}
Maybe try making a function like this... then when you're removing sprites
(before adding new copies of the same thing),
and between levels. I.e. when you removeChild(child) on everything, try calling
child.releaseMyTextures(); first?
Essentially, just don't call this function when there might be something with
the same texture still on screen.
public void releaseMyTextures(){
if ( texture_ != null && CCDirector.gl != null) texture_.releaseTexture(CCDirector.gl);
}
Let me know if this works.
Also, check the issue I posted last time if your labels are changing/updated
frequently, it's a one-line fix.
J
Original comment by wopstic...@gmail.com
on 29 Jun 2011 at 2:15
Hi,
Thanks for reply.
Yes I am adding lots of *different* sprites? i.e. multiple sprite sheets or
files for background/ground/sky sections for each level.
And I am also using timer label to show current time count which is called in
each frame.
I am adding two fixes suggested by you.
I will let you know if there is any improvement.
Thanks.
Original comment by rajnimge...@gmail.com
on 30 Jun 2011 at 8:24
[deleted comment]
The first function (cleanup override )will actually make things worse...
Try just calling the second one at the end of a level, or when you're sure
there are no identical sprites also on screen, and try the CCLabel fix.
Original comment by wopstic...@gmail.com
on 30 Jun 2011 at 8:55
Hi,
I am little confused.
Can you please let me know where should I put below function and from where to
call?
public void releaseMyTextures(){
if ( texture_ != null && CCDirector.gl != null) texture_.releaseTexture(CCDirector.gl);
}
WHAT I DID IS...
added two functions in CSprite.java
//##CHANGE_30062011
@Override
public void cleanup() {
super.cleanup();
if ( texture_ != null && CCDirector.gl != null) texture_.releaseTexture(CCDirector.gl);
}
//##CHANGE_30062011
public void releaseMyTextures(){
if ( texture_ != null && CCDirector.gl != null) texture_.releaseTexture(CCDirector.gl);
}
And modified removeChild in CCSprite.java to call releaseMyTextures as shown
below:
public void removeChild(CCNode node, boolean doCleanup) {
//##CHANGE_30062011
releaseMyTextures();
if( usesSpriteSheet_ ) {
CCSprite sprite = (CCSprite) node;
spriteSheet_.removeSpriteFromAtlas(sprite);
}
super.removeChild(node, doCleanup);
hasChildren_ = (children_.size() > 0);
}
Is this correct?
Please let me know if its wrong and how to fix it.
Thanks.
Original comment by rajnimge...@gmail.com
on 30 Jun 2011 at 12:40
Original issue reported on code.google.com by
rajnimge...@gmail.com
on 28 May 2011 at 10:50