Questions tagged [string-pool]

A string pool allows a runtime to save memory by preserving immutable strings in a pool, so that instances of common strings can be reused throughout the application instead of creating multiple instances of them.

In computer science, string interning is a method of storing only one copy of each distinct string value, which must be immutable. Interning strings makes some string processing tasks more time- or space-efficient at the cost of requiring more time when the string is created or interned. The distinct values are stored in a string intern pool.

Possible duplicate of .

133 questions
0
votes
1 answer

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 } Huge number of records have the same fileName…
dhythhsba
  • 972
  • 2
  • 11
  • 21
0
votes
1 answer

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 =…
shubham12511
  • 620
  • 1
  • 9
  • 25
0
votes
0 answers

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 separate web service requests uses same memory…
0
votes
0 answers

C, string intern pool and DLLs?

Many scripting languages have some form of C extensions. How do they resolve the problem of reference equality when interned strings / symbols can be either allocated from the main process or from the dll? Is there any form of initializing a String…
João Pires
  • 927
  • 1
  • 5
  • 16
0
votes
1 answer

In Java, when we print a string literal on to the terminal, does this string literal also be stored in the string pool?

I am aware that when we initialize a string literal to a variable this literal will be stored in the string pool by the JVM. Consider the piece of code below. System.out.println("This is a string literal"); Does the string literal within the quotes…
user13602601
0
votes
1 answer

String intern, String concatenation and String constant pool example in java

package com.lang; class StringConcatDemo2 { public static void main(String[] args) { String s1 = "Hello".concat("World"); // s1 to be created in heap. String s2 = s1.intern(); //Line-2 //Since "HelloWorld" doesn't exist in…
0
votes
2 answers

Unreachable literal created during "new String(..)"?

So a new String("abc"); creates an object in Heap & a literal "abc" in the String pool as per many of the answers I found. Since the new keyword was used, there should be no references to the String literal in the pool. Does this mean - a. The…
0
votes
2 answers

When a methd returns a String , will it be a literal or a String object?

Lets say a method returns a String String str = methodCall(); The return type of methodCall() is String. Will we get a String literal which will be in pool memory or just a String object?
0
votes
1 answer

Java - Regarding performance and memory use, why it's better to use a string into a static field instead of declaring it every time it's needed?

Why it's better to use a string into a static field instead of declaring it every time it's needed? // Old scenario Person p = new Person("Charles", "Xavier"); Person p = new Person("Charles", "Doe"); Person p = new Person("Charles", "Johnson"); //…
Leandro Maro
  • 325
  • 1
  • 12
0
votes
1 answer

why does a same interned String literal have multiple values in this java code snippet?

i found this thread How does this Java code snippet work? (String pool and reflection) talking about changing the value of a string using reflection. i perfectly understand the trick but with minor changes it does no more work as expected. could…
deiz21
  • 19
  • 4
0
votes
2 answers

Heap Memory Allocaton for same variable

String str = "Hello"; str = "Hello"; Above statements will create two objects on heap or same object will be return by jvm? Thanks in advance
sanil
  • 482
  • 1
  • 7
  • 23
0
votes
0 answers

Runtime constant pool location

The String objects are stored in heap. For example: String s1 = new String("s1"); s1 object will be stored in heap; The String literals are stored in string constant pool. String s2 = "s2"; s2 object will be stored in string constant pool…
Oleksandr Riznyk
  • 758
  • 1
  • 8
  • 19
0
votes
1 answer

When can a bad String Compare work? String Pooling VS6.0

Ran into a problem in VS2013, and was asking HOW COULD THIS HAVE EVER WORKED? A customer had the following macro in production. (specifics have been changed) #define IS_NONE( charPtr ) ( ( charPtr == "none" || charPtr == "N/A" ) ? TRUE : FALSE…
Ross Youngblood
  • 502
  • 1
  • 3
  • 16
0
votes
0 answers

Status of String objects after they are interned

String hello = new String(new char[]{'H', 'e', 'l', 'l', 'o'}); hello.intern(); I understand that when new operator is being used, hello variable refers to a String object on the heap. In the next line, since it is interned, a new object is…
Sara
  • 603
  • 8
  • 19
0
votes
0 answers

When is a string pool recycled in C#?

I know that string pools are associated with processes. And it will be recycled when the owner process exits or an application domain is unloaded. But I wonder if an application is long running, will the string pool leak memory?
shengjie
  • 1
  • 1
1 2 3
8 9