英文:
Does the memory reference for an object in heap ever run out of space?
问题
我最近正在复习大学的一堂课,脑海中突然冒出一个问题。自从我们使用new构造函数创建对象时,在堆内为该特定对象分配了一块内存空间。我想知道这个分配空间是否有可能因为任何原因而被填满。例如,对该对象执行操作,一个无限循环等。你们觉得呢?
英文:
I was recently going over a lecture for my college and a question popped in my mind. Since when we create objects with the new constructor, it allocates a memory space in the heap for that particular object. I wanted to know if it is ever possible for this allocated space to get filled up for any reason. For example, running operations on the object, an infinite-loop etc.
What do you guys think?
答案1
得分: 1
总之,是的,它可以。虽然堆可以增长和缩小,但它确实有下限和上限(通常由-Xms
和-Xmx
参数定义,除非您选择使用默认值)。如果超过堆大小,分配将失败,并且会收到java.lang.OutOfMemoryError
。
英文:
In a word, yes, it can. While the heap can grow and shrink, it does have lower and upper bounds (usually defined by the -Xms
and -Xmx
arguments, unless you choose to se the defaults). If the heap size is exceeded, the allocation will fail and you'll get a java.lang.OutOfMemoryError
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论