0

I'm running my PlayN-game in the browser. In my task manager I see how the memory of google chrome or firefox is getting bigger and bigger up to 512 MB.

The probable reason is that I don't clean up and destroy all my elements that I use in playn. I didn't clean up anything since the GarbageCollector was doing that in java for me and I didn't think about getting problems in HTML5.

So what is the easiest way to clean up everything (IFaces, Layers, Images...) after using it?

Can I just destroy the iface or the top layer and PlayN destroys all subelements for me? If I destroy an ImageLayer, the underlying Image is probably not destroyed, right?

Sorry for the unspecific question. I only need to understand the general concept and best practices for it.

4

1 回答 1

1

在大多数情况下,您唯一需要做的就是不要保留对不再需要的对象的引用。垃圾收集将为您处理剩下的事情。

您可以调用Layer.destroy以潜在地加速 GPU 内存的释放,但是当句柄被垃圾收集时,即使这样也会被释放。在 TriplePlay UI中,Interface.destroyRoot从 UI 中删除根(如果您要保留界面但不再需要该根,则需要这样做)并销毁根的层。

您可能遇到的问题是 HTML 后端当前缓存了游戏生命周期内的所有资源。因此,如果您加载大量图像或其他数据,最终将使用大量浏览器内存。任何给定的图像都不会被多次加载,但也许你的游戏中有很多图像。

我将在下一个 PlayN 版本之前更改此缓存无论您是否喜欢它的策略,因此如果您需要缓存图像,您必须自己缓存它们,但至少您也会能够在需要时释放它们。

于 2012-05-08T04:08:39.937 回答