j2me应用程序中的OutOfMemoryError [英] OutOfMemoryError in j2me application

查看:141
本文介绍了j2me应用程序中的OutOfMemoryError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在J2ME应用程序中得到 OutOfMemoryException

I am getting OutOfMemoryException in a J2ME Application.

如何找到导致此错误的原因?以及如何防止出现此错误?

How can I find what is causing this error? And how to prevent getting this error ?

我发出了一个http请求。请求未完成时,屏幕显示加载图像(如浏览器在加载页面时显示)。这是通过创建一个图像并重新绘制屏幕来完成的。

I make a http request. While the request isn't completed the screen shows a loading image (like a browser shows when a page is loading). This was done by creating an Image and repainting the screen.

创建图像1 - >重绘 - >创建图像2->重绘 - >创建图像3 - >重绘 - >创建图像1->重绘 - >。

create image 1 -> repaint -> create image 2-> repaint-> create image 3 -> repaint -> create image 1-> repaint -> .

我注意到(使用wtk内存监视器)这消耗了太多没有垃圾回收的内存。

I noticed (using wtk memory monitor) that this was consuming too much memory that wasn't garbage collected.

然后我尝试创建一个类图像池。这个类创建所有图像,然后显示它们。

Then I tried to create a class that is kind of pool of images. This class creates all the images and then show them.

创建图像1 - >创建图像2->创建图像3 - >重绘 - >重绘 - >重绘 - >重绘 - >重绘 - >。

create image 1 -> create image 2-> create image 3 -> repaint -> repaint -> repaint -> repaint -> repaint -> .

第二种情况似乎没有消耗内存而不是第一种情况。 (使用wtk内存监视器)。

This second scenario doesn't seem to consume as much as memory than the first one. (using wtk memory monitor).

但是,我认为(不确定是否这样)这两种方法都有助于导致此 OutOfMemoryException

However, I think (not sure if is this) those both approaches are contributing to cause this OutOfMemoryException.

推荐答案

错误原因是内存不足。很抱歉说明了,但你问: - )

The cause of the error is a lack of memory. Sorry to state the obvious, but you asked :-)

为了诊断确切的问题,需要一些源代码。

Some source code would be required in order to diagnose the exact problem.

您还应该查找代码的一部分,这些代码要么进行递归方法调用,要么在循环内部分配内存。递归调用通常会生成StackOverflowException,但值得一看。在循环内分配内存可能很快导致OutOfMemoryError。

You should also look for parts of your code that are either making recursive method calls or allocating memory inside a loop. Recursive calls would normally generate a StackOverflowException, but it's worth a look. Allocating memory inside a loop can quickly lead to an OutOfMemoryError though.

这篇关于j2me应用程序中的OutOfMemoryError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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