堆中对象的内存引用是否会耗尽空间?

huangapple go评论77阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年9月20日 22:39:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/63980122.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定