Avatar of gdlp2004
gdlp2004
 asked on

Question about Strings

If you initialize a String, and use it, once you are done with it for the duration of the class (say, if you were using it as a query string), will it improve performance and free up server memory if you then set it equals to null?

Thanks!
Java

Avatar of undefined
Last Comment
Webstorm

8/22/2022 - Mon
Webstorm

Hi gdlp2004,

yes, the string will be garbage collector, but you don't knwo when
ASKER CERTIFIED SOLUTION
Javatm

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Webstorm

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Webstorm

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Javatm

protected void finalize() throws Throwable {
    try {
        YourString = null;
    } finally {
        this.finalize();
    }
}
Webstorm

>>        this.finalize();
        super.finalize();
but finalize() is only invoked when the object is garbage collected
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Webstorm

... or when you explicitly call it, so it the same as directly setting the variable to null
Webstorm

Javatm

> but finalize() is only invoked when the object is garbage collected
> or when you explicitly call it, so it the same as directly setting the variable to null

Yap, correct I suggested that for formalization on suggesting garbage collection for all objects =)


⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Webstorm

:-)