Tag: 内存不足

Java需要新线程的内存

我有一个大规模创建线程的应用程序。 结果我得到一个OutOfMemoryError 。 我的想法是等到有足够的可用空间来创建下一个Thread 。 但是因此我需要知道创建一个线程需要多少内存以及这个内存是否可用。 有没有办法获得线程需要的内存量? 如何确定此内存量是否可用? 我已经尝试过的: for (int i = 0; i < links.size(); i++) { while(Runtime.getRuntime().maxMemory() – Runtime.getRuntime().totalMemory() + Runtime.getRuntime().freeMemory() < MEMORY_THRESHOLD) { synchronized (lock) { lock.wait(10); } } Thread t = new Thread(new Task(links.get(i))); t.setDaemon(true); t.start(); } 但即使我使用100MB作为阈值,我也会得到一个OutOfMemoryError 。

在尝试将大型json数据发送到android中的服务器时出现OutOfMemoryException?

我试图一次发送多个Json字符串[每个1 MB]到PHP Server。 当我试图发送10条记录时,其工作正常。 但如果超过20条记录则会显示OutOfMemoryException 。 我看到android内存大小限制为t0 15MB – 16MB。 但是没有任何线索如何解决这个问题,我使用下面的代码一次发送多条记录。 /** Upload Data*/ private void submitUploadData(String url, Map param) throws IOException { URL siteUrl; try { siteUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) siteUrl .openConnection(); conn.setRequestMethod(“POST”); conn.setDoOutput(true); conn.setDoInput(true); DataOutputStream out = new DataOutputStream(conn.getOutputStream()); String content1 = “”; Set getkey = param.keySet(); Iterator keyIter […]

Java堆空间 – -Xmx如何正常工作?

我在我的应用程序中遇到了臭名昭着的OutOfMemoryException ,而不是简单地增加可用堆空间的数量,我试图查看问题所在,以防万一,我的应用程序出现了某种泄漏。 我添加了JVM参数-XX:+ HeapDumpOnOutOfMemoryError ,当遇到OutOfMemory错误时会创建堆转储。 然后我分析了使用不同的分析工具生成的转储文件。 然后我开始使用-Xmx参数并观察模式。 令我困惑的是以下内容。 为什么在分析转储时我发现所有对象的总大小远小于我使用-Xmx参数设置的总大小? 例如,假设我将-Xmx设置为’2048m’。 当我分析转储文件时,我在堆上发现了总共400Mb的对象。 我期待找到2GB。 我错过了什么吗?

如何使用Java将> 1000 xml文件合并为一个

我试图将许多xml文件合并为一个。 我已经在DOM中成功完成了这项工作,但此解决方案仅限于几个文件。 当我在多个文件> 1000上运行它时,我得到一个java.lang.OutOfMemoryError。 我想要实现的是我有以下文件 档案1: …. 文件2: …… 档案n: …. 结果:输出: …. …. …. 这是我目前的实施: DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.newDocument(); Element rootSetElement = doc.createElement(“rootSet”); Node rootSetNode = doc.appendChild(rootSetElement); Element creationElement = doc.createElement(“creationDate”); rootSetNode.appendChild(creationElement); creationElement.setTextContent(dateString); File dir = new File(“/tmp/rootFiles”); String[] files = dir.list(); if (files == null) […]

如何避免java.lang.OutOfMemoryError?

我有两个简单的java代码。第一个定义恒定功率为power = a.pow(b); import java.math.BigInteger; public class FermatOne { public static void main(String[] args) { BigInteger a = new BigInteger (“2”); BigInteger k = new BigInteger (“15”); BigInteger c = new BigInteger (“1”); int b = 332192810; BigInteger n = new BigInteger (“2”); BigInteger power; power = a.pow(b); BigInteger exponent; exponent = k.multiply(power); BigInteger mod; […]

由大字符串引起的OutOfMemoryException

我使用以下方法从webapi捕获数据: public static String sendRequest(String requestURL, String data) throws IOException { URL url = new URL(requestURL + “?” + data); URLConnection conn = url.openConnection(); conn.setReadTimeout(10000); BufferedReader in = new BufferedReader(new InputStreamReader( conn.getInputStream())); String inputLine; StringBuilder answerBuilder = new StringBuilder(“”); try { while ((inputLine = in.readLine()) != null) answerBuilder.append(inputLine); in.close(); } catch (Exception e) { } […]

加载图像时出现内存不足错误

我想在android上加载一个图像 background = BitmapFactory.decodeResource(getResources(),R.drawable.hangmanbegin); background = Bitmap.createScaledBitmap(background,screenx,screeny,false); 图像是800 * 1280像素,所以如果我是正确的,它应该使用5MB的内存空间? 但是我的堆只是在那个阶段从15MB增长到29MB,所以没有窗口或上下文泄漏? 这是怎么解释的? 你能做些什么呢? Thnx提前!

java.lang.OutOfMemoryError:启动时的Java堆空间

几天前,我开始在MATLAB启动时遇到java.lang.OutOfMemoryError: Java heap spaceexception – 在我运行任何代码或向路径添加任何内容之前。 MATLAB加载的默认目录也没有文件。 我在Windows 7 64位上运行MATLAB R2012a。 可能是什么导致了这个?

java.lang.OutOfMemoryError:无法分配带有16777216个空闲字节的571401228字节分配和直到OOM的495MB

我的android应用程序出错了。 我想使用viewPager作为android图像滑块,为此我得到了我的AndroidImageAdapter.java,但是当涉及方法instantiateItem时,应用程序中止,我不知道如何修复它。 我已经查看了失败并添加了 android:hardwareAccelerated=”false” android:largeHeap=”true” 我的清单,但它仍然存在。 这是完整的错误代码: java.lang.OutOfMemoryError: Failed to allocate a 571401228 byte allocation with 16777216 free bytes and 495MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:856) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:675) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:2228) at android.content.res.Resources.loadDrawableForCookie(Resources.java:4211) at android.content.res.Resources.loadDrawable(Resources.java:4085) at android.content.res.Resources.getDrawable(Resources.java:2005) at android.content.res.Resources.getDrawable(Resources.java:1987) at android.content.Context.getDrawable(Context.java:464) at android.widget.ImageView.resolveUri(ImageView.java:827) at android.widget.ImageView.setImageResource(ImageView.java:434) at bubusapp.anni.privateapplication.com.schnurr.asam.robin.bubusapp.AndroidImageAdapter.instantiateItem(AndroidImageAdapter.java:50) at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1002) at android.support.v4.view.ViewPager.populate(ViewPager.java:1150) […]

Hibernate:OutOfMemoryError:PermGen空间

谁能说我的申请有什么问题? public class HibernateUtil { private static final SessionFactory sessionFactory; static { try { sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); } catch (Throwable ex) { System.err.println(“Initial SessionFactory creation failed.” + ex); throw new ExceptionInInitializerError(ex); } } public static SessionFactory getSessionFactory() { return sessionFactory; } } public boolean insertUser(User user) { Session session = HibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction(); […]