Skip to main content
Filter by
Sorted by
Tagged with
12 votes
2 answers
224 views

Increased memory consumption due to String Constant Pool behavior after upgrading from Java 17 to Java 21

While upgrading our project from Java 17 to Java 21, we noticed an increase in memory consumption. After dumping the heap and analyzing the differences, I found that there are thousands of empty ...
Voy's user avatar
  • 145
1 vote
3 answers
250 views

Java String intern function and ==

Recently I'm learning Hotspot JVM. When learning the string constant pool and String intern function, I encountered a very weird situation. After browsing a lot of answers, I still can’t explain this ...
DracoYu's user avatar
  • 37
2 votes
0 answers
49 views

Python multiple strings point to same heap memory object if value have less than 4 DIFFERENT characters [duplicate]

in addition to the answers provided here For example : q = "asdasdasdsadsadsadsadsadsadsadsadsad" a = "asdasdasdsadsadsadsadsadsadsadsadsad" >>> a is q True even though ...
Spyros Kappalamda's user avatar
-1 votes
3 answers
93 views

How many Strings are formed? [duplicate]

String a="hello"; String b=a+"Bye"; How many Strings are formed? From my understanding of Java. What happens in this code is: String a="hello"; // hello is created in ...
Joshua Samuel's user avatar
71 votes
1 answer
2k views

Why does String creation using `newInstance()` method behave different when using `var` compared to using explicit type `String`?

I am learning about reflection in Java. By accident, I discovered the following, for me unexpected behavior. Both tests as written below succeed. class NewInstanceUsingReflection { @Test void ...
hanszt's user avatar
  • 583
1 vote
1 answer
666 views

Problems re-appending spaces to a string in python

I have a problem where I'm trying to take the text string string "The quick brown fox jumps over the extraordinarily lazy dog" and convert it into an array of characters whilst also storing ...
Damon O'Neil's user avatar
0 votes
2 answers
168 views

what will happen if our String Memory is full in Java 8 in a real life application [duplicate]

I am currently working on java 8 Project from last 4 years. In an interview, I was being asked what will happen if your String pool is full. Never encountered it. Already searched a lot didnt find any ...
NEHA's user avatar
  • 9
0 votes
2 answers
230 views

Java Strings - What is the difference between "Java" and new String("Java")? [duplicate]

Given this example code: class basic { public static void main(String[] args) { String s1 = "Java"; String s2 = new String("Java"); } } Are s1 and s2 both ...
Andrew's user avatar
  • 11
2 votes
2 answers
751 views

Are string objects and their literals garbage collected?

I have some questions revolving around the garbage collection of string objects and literals and the string pool. Setup Looking at a code snippet, such as: // (I am using this constructor on purpose) ...
vishal joshi's user avatar
1 vote
1 answer
917 views

How to modify the size of String Pool in JVM?

I was reading a book on Java and there was an option mentioned to modify the size of the String Pool, and that option was XX:StringTableSize. When I tried this in my command line, I got an error ...
HusenPatel's user avatar
0 votes
1 answer
318 views

What is the best way to evict unused records from string pool?

I am implementing a cache in Golang. Let's say the cache could be implemented as sync.Map with integer key and value as a struct: type value struct { fileName string functionName string } ...
dhythhsba's user avatar
  • 1,032
3 votes
1 answer
485 views

Java char array to String without creating new objects

When creating a String like this: String s1 = “ABC” the JVM will look in the String pool if "ABC" exists there and create a new object only if "ABC" doesn't exist yet. So the ...
Sadık's user avatar
  • 4,419
0 votes
1 answer
449 views

In Java Is it efficient to use new String() instead of double quotes when string is really large and not using again?

I have so many use cases where I have to initialize a large string and not use the same string anywhere else. //Code-1 public class Engine{ public void run(){ String q = "...
stux_kill's user avatar
  • 620
0 votes
0 answers
70 views

When string pool GC string value ? Calling a web service two times uses same string value in string pool OR each time value GC & created again

If string pool caches the string values then till what time it keeps values into the memory. When it sends those values to GC. If I send two call request of a same REST web service then Does this two ...
praveen kumar's user avatar
2 votes
1 answer
187 views

How does String concatenation work in terms of the String Pool? [duplicate]

13: String a = ""; 14: a += 2; 15: a += 'c'; 16: a += false; 17: if ( a == "2cfalse") System.out.println("=="); 18: if ( a.equals("2cfalse")) System.out....
S. Tiss's user avatar
  • 319

15 30 50 per page
1
2 3 4 5
9