Replies: 2 comments
-
String literal로 생성한 객체는 Heap 영역 내 String Constant Pool에 저장되어 재사용됩니다. 즉, 내용이 같다면 동일한 메모리 주소를 참조합니다. 반면 new 키워드를 사용해 생성한 String 객체는 같은 내용이더라도 여러개의 객체가 각각 Heap 영역을 차지하게 됩니다. 메모리를 효율적으로 사용하기 위해서는 String literal로 String을 생성하여 String pool을 사용하는 것이 좋습니다. |
Beta Was this translation helpful? Give feedback.
0 replies
-
스트링 리터럴로 생성된 객체는 JVM 힙 영역의 String Pool에 생성됩니다. String Pool에서 문자열 리터럴은 하나의 인스턴스로 유지됩니다. 이후 동일한 스트링 리터럴에 대해 String Pool의 문자열을 공유할 수 있습니다. 이를 통해 메모리를 절약하고 성능을 향상시킵니다. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
.
Beta Was this translation helpful? Give feedback.
All reactions