Sudhanshu Gupta wrote:is there any way we can access the global String literal pool?
say print the litrals in the pool at any given time or calculate the memory usage by the pool?
You can access the SCP through intern() method of the String class, that is if you need to find a reference from a SCP for a given String or need to add a String to the SCP. SCP is for JVM's internal usage, so not sure whether it's possible to access the values in the SCP etc..
hi Vijitha Kumara
thank you very much.
I knew about the intern() method.
I was just wondering if there is anyway to access the pool.
I read somewhere that Console.readPassword() method returns a char array
of security reasons to prevent a hacker to read the password from the string pool.
This made me think does java allows access to the pool?
Thanks. I got your point.
however i really think lifetime of a string data in the memory is certainly related to the SCP.
The lifetime of a string constant is longer than other objects as it is preserved in the SCP
by the JVM. Thus
To minimize the lifetime of sensitive data in memory it is adviced to manually make the char array empty.
so that it becomes available for GC.
About accessing the contents of a part of memory (including the SCP) should be a matter of some hardware interaction techniques.
so we dont need to discuss it here.
I just wanted to clarify if java provides any way to access the contents of the SCP. And that has already been clarified
thanks to you.
Thank you again Vijitha for your inputs.