gpt4 book ai didi

android - 我的游戏有内存泄漏

转载 作者:行者123 更新时间:2023-11-29 01:33:05 25 4
gpt4 key购买 nike

我正在开发一个简单的游戏。我正在监视堆大小,它正在慢慢增加到 48mb 的最大限制。但是,我在我的代码中没有看到任何会导致如此高内存使用率的内容。我所做的就是在屏幕上画九个圆圈并在它们周围设置阴影。任何帮助将不胜感激谢谢!

 public void run() {
Log.d("Speed Buttons", "Background thread has started");
//standard game loop
Canvas canvas;
while(isRunning == true)
{



if(!holder.getSurface().isValid()) {
continue;
}

canvas = holder.lockCanvas();
//call dodraw method
doDraw(canvas);


holder.unlockCanvasAndPost(canvas);

}


}


protected void doDraw(Canvas canvas)
{
Paint circle = new Paint();
circle.setColor(Color.BLUE);

//creates a glow around the circles
circle.setShadowLayer(5,0,0,Color.RED);

op.setWidthSetHeight(getWidth(), getHeight());
int big = 130;
op.setBig(130);


//I have to use getwidth and getheight in draw, because in context, it would include the title bar and status bar
//circle 5
//using convertDP to pixel for everything

canvas.drawCircle(getWidth()/2,getHeight()/2,op.convertDpToPixel(6000),circle);

//circle 2
canvas.drawCircle(getWidth()/2,getHeight()/2-big*scale,op.convertDpToPixel(6000),circle);
//circle 1
canvas.drawCircle(getWidth()/2-(big*scale),getHeight()/2-big*scale,op.convertDpToPixel(6000),circle);
//circle 3
canvas.drawCircle(getWidth()/2+ (big*scale),getHeight()/2-big*scale,op.convertDpToPixel(6000),circle);
//circle 8
canvas.drawCircle(getWidth()/2,getHeight()/2+big*scale,op.convertDpToPixel(6000),circle);
//circle 4
canvas.drawCircle(getWidth()/2-(big*scale),getHeight()/2,op.convertDpToPixel(6000),circle);
//circle 6
canvas.drawCircle(getWidth()/2+(big*scale),getHeight()/2,op.convertDpToPixel(6000),circle);
//circle 7
canvas.drawCircle(getWidth()/2-(big*scale),getHeight() / 2 + big * scale, op.convertDpToPixel(6000), circle);
//circle 9
canvas.drawCircle(getWidth()/2+(big*scale),getHeight()/2+big*scale,op.convertDpToPixel(6000),circle);










}

最佳答案

所有对 drawCircle 的调用都可能在堆中创建局部变量。垃圾收集器应该处理它们,这就是它关闭的原因。你有什么问题吗?还是只是一个问题?

关于android - 我的游戏有内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30173012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com