简体   繁体   English

Android内存不足错误

[英]Android Out of Memory Error

In my Activity, i'm trying to do a bit of image processing of my own. 在我的活动中,我尝试自己做一些图像处理。 I have algorithms that manipulate the image the way I want to, which is the object LabAware. 我有一些算法可以按照我想要的方式操作图像,这就是对象LabAware。 I have noticed that when I comment out the last 3 lines of codes, i don't get a Out of Memory Error. 我注意到,当我注释掉最后三行代码时,没有出现内存不足错误。 Also, I pass an Bitmap in my algorithm, where I do image processing and accessing of pixels. 另外,我在算法中传递了一个位图,在其中进行图像处理和像素访问。 I also added the android:largeHeap = "true; statement in my manifest file. How do I tackle the Out of Memory Error? 我还在清单文件中添加了android:largeHeap =“ true;语句。如何解决内存不足错误?

Drawable drawable = getResources().getDrawable(R.drawable.test);
Bitmap image = ((BitmapDrawable) drawable).getBitmap();
Bitmap imageTwo = image.createBitmap(900,1200, Bitmap.Config.ARGB_8888);
grayImage = Bitmap.createScaledBitmap(image,900,1200,false);
//grayImage is a public member variable of the activity

LabAware  lab = new LabAware();
lab.calculateChip(grayImage,852 ,420);
printInt(lab.green1);

You can try using android:largeHeap="true" . 您可以尝试使用android:largeHeap="true" If that only delays the crash, you probably have a memory leak. 如果这样只会延迟崩溃,则可能是内存泄漏。 The allocation that triggers the crash usually has nothing to do with the problem, so the stack trace will be useless. 触发崩溃的分配通常与该问题无关,因此堆栈跟踪将毫无用处。 You need to dump the heap and look for objects that shouldn't be there. 您需要转储堆并查找不应存在的对象。 Find out what's holding a reference to them, then study your code to find out why. 找出导致它们引用的原因,然后研究代码以找出原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM