Link to home
Start Free TrialLog in
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!
Avatar of Webstorm
Webstorm

Hi gdlp2004,

yes, the string will be garbage collector, but you don't knwo when
ASKER CERTIFIED SOLUTION
Avatar of Javatm
Javatm
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
protected void finalize() throws Throwable {
    try {
        YourString = null;
    } finally {
        this.finalize();
    }
}
>>        this.finalize();
        super.finalize();
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
> 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 =)