退出屏幕,导致Java本机内存增加 [英] Exit screen causing Java native memory to grow

查看:75
本文介绍了退出屏幕,导致Java本机内存增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用LibGDX游戏

我有一个大厅屏幕 在大厅"屏幕中,我可以转到

I have a Lobby Screen From the Lobby Screen I can go to

  Game 1
  Game 2
  Game 3
  Game 4

例如,当我退出游戏1时,我会回到大厅 现在我可以选择第3场了

When I exit Game 1 (for example) I return back to the Lobby Which allows me now to pick Game 3 (for example)

我要注意的是Java本机内存正在增长
当我玩大厅->游戏1->大厅->游戏2->大厅->游戏3->大厅->游戏4…

What I'm noticing is the java native memory is growing
When I do Lobby -> Game 1 -> Lobby -> Game 2 - > Lobby -> Game 3 -> Lobby - > Game 4 …

我在大堂

switch (selection) {
  case 1: NewStage = new Game1Screen();  break;
  case 2: NewStage = new Game2Screen();  break;
  case 3: NewStage = new Game3Screen();  break;
  case 4: NewStage = new Game4Screen();  break;
}
game.setScreen (NewStage);

这成功地将我带到了新游戏中

This successfully takes me off to the new Game

现在我在游戏屏幕中

switch (state) {
   case EXITING:   this.dispose();
                   game.setScreen(Lobby);    <<-- probably causing the memory growth
                   break;
}

我认为这不会完全关闭该级别,从而导致Java本机内存增长.

I don't think this is completely shutting down the level and thus causing Java Native Memory to grow.

退出游戏后,我想关闭并完全销毁游戏,而我们又回到了大厅.

I want to shutdown and completely destroy the Game once it has been exited and we are back at the Lobby.

推荐答案

这是非常libgdx的奇怪政策,尤其是我是android开发人员.

It's very libgdx strange policy, especially that I'm android developer.

dispose函数声明为hide,但从未从系统调用.现在我只看到两种方法.

dispose function declared as hide, but never called from system. Now I see only two ways.

首先,就像之前已经写过的一样-将所有可用资源操作移至hide,因为hide在更改屏幕或关闭应用程序时会自动调用.

First, as already write before - move all free resources actions at hide, because hide auto called on change screen or close application.

第二,实现所有者ScreenAdapter,并在hide处手动调用dispose.

Second, implement owner ScreenAdapter and manual call dispose at hide.

这篇关于退出屏幕,导致Java本机内存增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆