Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can String objects cause outofmemory error?  RSS feed

 
Ranch Hand
Posts: 30
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As we all know that Strings objects are created in permanent generation area.which is never garbage collected.So,can String objects cause outofmemoryerror?
 
lowercase baba
Bartender
Posts: 12613
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If they use memory, then of course they can. Also, not all strings go in the string pool..only string literals.
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
even if we say string constant pool is a dynamic container, if it holds too many strings, say, that occupy the memory more than what the limited memory system underneath could allocate, it surely would.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12613
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I understand it, you get an OOM error when you can't get more memory when you need it. So you hit some line of code that basically says "...new(something)". The JVM says "I need X more bytes to create that, but I only have Y available." It really doesn't matter what that new object is, or what's already in memory, the only thing that matters is that you need more memory and the JVM doesn't have it, and can't free anything up.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!