我的应用有些问题。有时它会滞后并给我“GC_CONCURRENT释放”。我使用MAT来查看消耗如此多内存的内容,并且我发现对象列表占用了大量内存。问题是我的游戏中有块,我需要看看我的玩家是否踩到它们,这就是我使用这个列表的原因。我目前有200块,但我会有更多,我不认为他们应该使用这么多内存,我该怎么办才能解决这个问题?这是块类的外观:
package com.NeverMind.DontFall.android;
import android.util.Log;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
/**
* Created by user on 20-Aug-15.
*/
public class blockClass {
private SpriteBatch spriteBatch;
public float x, y, sizeX = 100, sizeY = 100, startTime;
private boolean isTouched = false;
private Texture texture;
Sprite blockSprite;
public blockClass(float sentX, float sentY, Texture sentTexture, float scaleX, float scaleY){
x = sentX;
y = sentY;
sizeY *= scaleY;
sizeX *= scaleX;
spriteBatch = new SpriteBatch();
texture = sentTexture;
blockSprite = new Sprite(texture);
startTime = System.currentTimeMillis();
}
public void draw(float cameraX, float cameraY) {
spriteBatch.begin();
spriteBatch.draw(blockSprite, x + cameraX, y + cameraY, sizeX, sizeY);
spriteBatch.end();
}
public void update(float posX, float posY, boolean immune){
if (isTouched == false && immune == false)
if (touched(posX, posY) )
isTouched = true;
if (isTouched == true) {
y -= 10;
}
}
public boolean touched (float posX, float posY)
{
if (posX >= x && posX < x + sizeX && posY == y + sizeY)
return true;
return false;
}
public boolean toKill (float posY){
if (isTouched && y < posY - 1000)
return true;
return false;
}
}
答案 0 :(得分:5)
GC_CONCURRENT freed
表示调用垃圾收集器是因为杀死了对象(例如将null
分配给它们)。
有一个概念调用Object Pooling,它重用死对象而不是杀死它并从池中获取对象而不是创建一个新对象,所以你没有GC调用,同样没有GC_CONCURRENT freed
。< / p>