Android Jit:将JitTable从512调整为1024,依此类推。。。。这是什么?

Android Jit:将JitTable从512调整为1024,依此类推。。。。这是什么?,android,memory-leaks,jit,dalvik,Android,Memory Leaks,Jit,Dalvik,开发android应用程序已经有好几个星期了,我才意识到我在catlog中收到了这样的信息: Jit: Resizing JitTable from 512 to 1024 (...) Jit: Resizing JitTable from 1024 to 2048 (...) Jit: Resizing JitTable from 2048 to 4096 这是什么意思?是内存泄漏还是类似的问题 我在(…)区域也得到了这个: 大约14%的免费,我撞车了 当我单击菜单按钮(更改活动)时会发

开发android应用程序已经有好几个星期了,我才意识到我在catlog中收到了这样的信息:

Jit: Resizing JitTable from 512 to 1024 
(...)
Jit: Resizing JitTable from 1024 to 2048 
(...)
Jit: Resizing JitTable from 2048 to 4096
这是什么意思?是内存泄漏还是类似的问题

我在(…)区域也得到了这个:

大约14%的免费,我撞车了

当我单击菜单按钮(更改活动)时会发生这种情况。 我在模拟器中测试,不知道在手机中的结果

logcat中崩溃时的错误:

04-24 08:26:34.158: E/GraphicsJNI(482): VM won't let us allocate 1536000 bytes
04-24 08:26:34.158: D/dalvikvm(482): GC_FOR_MALLOC freed 0K, 64% free 4280K/11655K, external 11662K/13614K, paused 72ms
04-24 08:26:34.158: D/skia(482): --- decoder->decode returned false
04-24 08:26:34.168: D/AndroidRuntime(482): Shutting down VM
04-24 08:26:34.168: W/dalvikvm(482): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-24 08:26:34.218: E/AndroidRuntime(482): FATAL EXCEPTION: main
04-24 08:34:37.807: E/AndroidRuntime(522): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
04-24 08:26:34.218: E/AndroidRuntime(482): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.KeySoft.OpenGuide/com.KeySoft.OpenGuide.Favourites}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
04-24 08:34:37.807: E/AndroidRuntime(522):  at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-24 08:34:37.807: E/AndroidRuntime(522):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:470)
04-24 08:34:37.807: E/AndroidRuntime(522):  at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:284)
04-24 08:34:37.807: E/AndroidRuntime(522):  at com.KeySoft.OpenGuide.Top20.readBitmapImage(Top20.java:483)
04-24 08:34:37.807: E/AndroidRuntime(522):  at com.KeySoft.OpenGuide.Top20.addShopToList(Top20.java:251)
04-24 08:34:37.807: E/AndroidRuntime(522):  at com.KeySoft.OpenGuide.Top20.SqlShopsVissza(Top20.java:439)
04-24 08:34:37.807: E/AndroidRuntime(522):  at com.KeySoft.OpenGuide.Top20.onCreate(Top20.java:182)
04-24 08:34:37.807: E/AndroidRuntime(522):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-24 08:34:37.807: E/AndroidRuntime(522):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-24 08:34:37.807: E/AndroidRuntime(522):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-24 08:34:37.807: E/AndroidRuntime(522):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-24 08:34:37.807: E/AndroidRuntime(522):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-24 08:34:37.807: E/AndroidRuntime(522):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 08:34:37.807: E/AndroidRuntime(522):  at android.os.Looper.loop(Looper.java:130)
04-24 08:34:37.807: E/AndroidRuntime(522):  at android.app.ActivityThread.main(ActivityThread.java:3683)
04-24 08:34:37.807: E/AndroidRuntime(522):  at java.lang.reflect.Method.invokeNative(Native Method)
04-24 08:34:37.807: E/AndroidRuntime(522):  at java.lang.reflect.Method.invoke(Method.java:507)
04-24 08:34:37.807: E/AndroidRuntime(522):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-24 08:34:37.807: E/AndroidRuntime(522):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-24 08:34:37.807: E/AndroidRuntime(522):  at dalvik.system.NativeStart.main(Native Method)
04-24 08:26:34.158:E/GraphicsJNI(482):VM不允许我们分配1536000字节
4-24 08:26:34.158:D/dalvikvm(482):释放0公里的马洛克的GC_,64%的自由4280K/11655K,外部11662K/13614K,暂停72毫秒
04-24 08:26:34.158:D/skia(482):---解码器->解码返回false
04-24 08:26:34.168:D/AndroidRuntime(482):关闭虚拟机
04-24 08:26:34.168:W/dalvikvm(482):threadid=1:线程以未捕获异常退出(组=0x40015560)
04-24 08:26:34.218:E/AndroidRuntime(482):致命异常:主
04-24 08:34:37.807:E/AndroidRuntime(522):java.lang.OutOfMemory错误:位图大小超出VM预算
04-24 08:26:34.218:E/AndroidRuntime(482):java.lang.RuntimeException:无法启动活动组件信息{com.KeySoft.OpenGuide/com.KeySoft.OpenGuide.favorities}:android.view.InflateException:二进制XML文件行#2:膨胀类时出错
04-24 08:34:37.807:E/AndroidRuntime(522):在android.graphics.BitmapFactory.NativeDecodeseam(本机方法)
04-24 08:34:37.807:E/AndroidRuntime(522):在android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:470)
04-24 08:34:37.807:E/AndroidRuntime(522):位于android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:284)
04-24 08:34:37.807:E/AndroidRuntime(522):位于com.KeySoft.OpenGuide.Top20.readBitmapImage(Top20.java:483)
04-24 08:34:37.807:E/AndroidRuntime(522):位于com.KeySoft.OpenGuide.Top20.addShopToList(Top20.java:251)
04-24 08:34:37.807:E/AndroidRuntime(522):位于com.KeySoft.OpenGuide.Top20.sqlshopsvisza(Top20.java:439)
04-24 08:34:37.807:E/AndroidRuntime(522):位于com.KeySoft.OpenGuide.Top20.onCreate(Top20.java:182)
04-24 08:34:37.807:E/AndroidRuntime(522):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)上
04-24 08:34:37.807:E/AndroidRuntime(522):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-24 08:34:37.807:E/AndroidRuntime(522):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-24 08:34:37.807:E/AndroidRuntime(522):在android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-24 08:34:37.807:E/AndroidRuntime(522):在android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-24 08:34:37.807:E/AndroidRuntime(522):在android.os.Handler.dispatchMessage(Handler.java:99)上
04-24 08:34:37.807:E/AndroidRuntime(522):在android.os.Looper.loop(Looper.java:130)上
04-24 08:34:37.807:E/AndroidRuntime(522):位于android.app.ActivityThread.main(ActivityThread.java:3683)
04-24 08:34:37.807:E/AndroidRuntime(522):位于java.lang.reflect.Method.Invokenactive(本机方法)
04-24 08:34:37.807:E/AndroidRuntime(522):位于java.lang.reflect.Method.invoke(Method.java:507)
04-24 08:34:37.807:E/AndroidRuntime(522):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-24 08:34:37.807:E/AndroidRuntime(522):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-24 08:34:37.807:E/AndroidRuntime(522):在dalvik.system.NativeStart.main(本机方法)
我在模拟器上使用256 MB Ram。。。也许我可以用真正的设备来避免这些?
便宜的设备也有至少384 MB的内存(Galaxy Mini),但更多…

正如您在评论中所问的那样,我使用的是800x480图像。如何用较小的尺寸制作出好的背景?

下面是一段允许您调整位图大小的代码

public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {

int width = bm.getWidth();

int height = bm.getHeight();

float scaleWidth = ((float) newWidth) / width;

float scaleHeight = ((float) newHeight) / height;

// create a matrix for the manipulation

Matrix matrix = new Matrix();

// resize the bit map

matrix.postScale(scaleWidth, scaleHeight);

// recreate the new Bitmap

Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);

return resizedBitmap;

}
问题1: 它没有泄漏内存。JitTable用于存储jni引用。例如,当您调用NewGlobalRef Api时,JitTable将增加1条记录

这意味着JitTable不够,VM将自动调整大小。所以别担心,您只需保留正确的参考。没关系

问题2:
GC_EXTERNAL_ALLOC,当您分配本机内存但内存不足时,将调用GC。 GC_并发,当您分配的对象大小大于384K时

这表示您正在使用内存。如果您的应用程序崩溃,请发布您收到的错误消息。这些只是关于垃圾收集和即时编译器的信息。这可能是因为你使用了太多的内存或者有漏洞。我猜你使用的是大图像。与第2行的布局xml文件相关的地方。由于每个应用程序的内存有限(比如16MB),所以在使用图像时必须非常保守。100万像素(1000x1000)的图像已经需要4兆字节的ram。我使用的是800x480图像。如何用较小的尺寸制作好背景?如果我把它减半,它会是一样的吗?这是因为超过了每个应用程序的内存限制。与JIT编译器无关。像
hprof
和eclipsemat这样的工具可以帮助找出内存的去向。
public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {

int width = bm.getWidth();

int height = bm.getHeight();

float scaleWidth = ((float) newWidth) / width;

float scaleHeight = ((float) newHeight) / height;

// create a matrix for the manipulation

Matrix matrix = new Matrix();

// resize the bit map

matrix.postScale(scaleWidth, scaleHeight);

// recreate the new Bitmap

Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);

return resizedBitmap;

}