- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
由于嵌套构造函数调用,我有以下代码及其抛出 StackOverflowException,并且我知道仅当构造函数成功运行时才会分配内存。
package interview;
public class StackOverflow {
int i;
StackOverflow()
{
System.out.println(" i= "+i);
System.out.println("in Constructor");
StackOverflow sOf = new StackOverflow();
sOf.i=5;
System.out.println(" i= "+i);
}
public static void main(String[] args) {
System.out.println("in main");
StackOverflow s = new StackOverflow();
s.i=10;
System.out.println(" i= "+s.i);
}
}
所以我的疑问是“i”的值发生了什么?它是否存储在堆栈或堆中的某个位置?在什么情况下上面的代码会抛出以下异常?
OutOfMemoryException
最佳答案
OutOfMemoryError:当 Java 虚拟机因内存不足而无法分配对象且垃圾收集器无法提供更多内存时抛出该错误。
StackOverflowError:由于应用程序递归太深而发生堆栈溢出时抛出。
in which case it can throw OutOfMemoryError?
你的构造函数正在递归地调用自身,进入更深层,在 JVM 内存不足之前堆栈溢出。
使用for
循环而不是递归来创建过多的对象。你也许能够看到 OutOfMemoryError
。
My question is what is happening to the value of i( it is getting stored heap or stack):
A Java Virtual Machine stack is analogous to the stack of a conventional language such as C: it holds local variables and partial results, and plays a part in method invocation and return.
由于堆是对象的存储,而 i
是对象的字段成员StackOverflow
类,它存储在 Heap
关于java - 为什么这段代码抛出 StackOverflowException 而不是 OutOfMemoryException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19532661/
我已经花了几周的时间来解决这个问题。但我仍然无法解决这个问题。 我在 angularjs 中使用 http 调用 Web API 服务 $http({
我的转储文件包含 OutOfMemoryException 但所有对象字段似乎都为空。这只是一个误报还是有办法知道这个异常(exception)? 0:052> !do 000000027fff10e
我使用的项目包含许多从单个基类继承的类。在单元测试中,我需要按类型和数据比较收到的结果。 当我在条件列表包含足够多的不同条件的情况下使用类型匹配比较时,编译器会抛出 OutOfMemoryExcept
我的应用程序在 512mb 手机模拟器上运行时突然崩溃(可重现)(只有 920 来测试)。没有任何异常,它只是变黑了。然后我在应用程序上运行分析工具,发现内存在应用程序崩溃时达到了极限。应用程序退出并
我试图弄清楚应该如何使用 MemoryCache 以避免出现内存不足异常。我来自 ASP.Net 背景,缓存管理它自己的内存使用,所以我希望 MemoryCache 会做同样的事情。正如我制作的波纹管
我从某个生产代码版本中获得了异常日志。 System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was
比如说,我们有一个表,其中包含一些包含 jpg 文件二进制数据的大型 text 字段。任务是从磁盘上的数据库中获取这些文件。因此,起初我决定执行以下操作: MyDataContext dc = new
在 Windows 窗体 C# 应用程序中,我有一个文本框,用户可以在其中粘贴日志数据,并对其进行排序。我需要单独检查每一行,所以我按新行拆分输入,但如果有很多行,超过 100,000 行左右,它会抛
我们正在将一个大的平面文件加载到 BizTalk Server 2006(原始版本,不是 R2)中 - 大约 125 MB。我们针对它运行一个映射,然后获取每一行并调用一个存储过程。 我们在编排处理期
比如说,我们有一个表,其中包含一些包含 jpg 文件二进制数据的大型 text 字段。任务是从磁盘上的数据库中获取这些文件。因此,起初我决定执行以下操作: MyDataContext dc = new
在我的应用程序中,用户可以启动相机 Intent 并拍照并将其保存到自定义文件夹中。然后他们可以重新启动相机拍摄另一张照片等。因此最终用户可以拍摄多张照片。 我遇到的问题是,在我的画廊中,当我尝试将所
在 Windows 窗体 C# 应用程序中,我有一个文本框,用户可以在其中粘贴日志数据,并对其进行排序。我需要单独检查每一行,所以我按新行拆分输入,但如果有很多行,超过 100,000 行左右,它会抛
我收到 OutOfMemoryException,而堆似乎仍然有足够的剩余空间。 我自己的日志报告 - VM 内存使用了 48G 中的 22.28G 来自-XX:+PrintGCDetails -XX
给定一个简单的案例类 case class Rating(user: Int, item: Int, rating: Double) 和两个RDD[Rating]:我们得到的 OOME 在两个 R
我正在开发一个应用程序,该应用程序使用移动设备拍照并使用网络服务发送照片。但是在我拍了 4 张照片之后,我在下面的代码中得到了一个 OutOfMemoryException。我尝试调用 GC.Coll
我想调整我网站中图片的大小,但是当我使用 Bitmap 加载 14032*19864(png 扩展名)的图片时,抛出 OutOfMemoryException。我的编译器配置是 any cpu。我在怀
在我的应用程序中,我正在使用 Windows 服务读取文件。该服务每秒读取一次文件。这是我用来读取文件的代码: public static byte[] GetBytesFromFile(string
我正在尝试将用户的整个桌面捕获为图像。我通过以下方式执行此操作: public Bitmap CaptureScreen() { // Set up a bit
我正在开发一个 64 位 .Net Windows 服务应用程序,该应用程序本质上加载了一堆数据以供处理。在执行数据量测试时,我们能够压倒该进程并抛出 OutOfMemoryException(我没有
我知道我的问题没有简单的答案,但我会很感激想法、指南或某种要看的东西列表 我有一个不断抛出 OutOfMemoryException 异常的网络 Windows 服务。该服务有两个针对 x86 和 x
我是一名优秀的程序员,十分优秀!