I have a
GameScene which has a character (animated sprite),
AutoParallaxBackground background with quite large textures and no more than 3 other items attached to the scene at a time, previous 3 items are
dispose()-ed accordingly, background music and item sounds. Background music is instantiated with
MusicFactory, Sounds are played on
SoundPool. In between switching these scene we are loading resources asynchronously, reading the streams and instantiation is done in
AsyncTask and the loading textures to the hardware is done on
GLThread. If I turn off the background music, this starts to happen totally random.
I'm experiencing scene junking on at first flow:
MenuScene -> 1st Stage (
GameScene). After a while lag does not happen, rather than occasionally or random. Junk is happening when aforementioned 3 items are attached on the Scene and a sound is played along, note that background music is playing at the same time.
Detaching previous 3 items is "optimized" to reduce GC calling almost perfectly. When the lag occurs
GC_EXPLICIT is showed in the logcat.
What I have tried:
- Playing the sounds and music on different thread,
IntentService, dedicated Service.
Reduced calls to
mScene.detachChild(child)and other scene methods to avoid iterations over children of the scene.
IEntitys with matcher to avoid iteration.
- Inspected sound files' integrity with ffmpeg for possible errors
.dispose(), unloading the textures from hardware or
detachChild() causing this junk?
Could be marked object for GC from the async tasks be causing this?
What else could be contributing to this issue?