Simple Memory question
Hello I have a short question about memory mangagement in Java.
If i have this function inside a class:
...
public void createUser( User user )
{
...this.user = user;
...ormapper.start();
...ormapper.save(this.user);
...ormapper.end();
...this.user = null;
}
...
When i call this function, does it matter if i make this.user null ? (i won't use the class or function anymore)
Or does Java do it itself?
Also, on a webpage, is it usefull to make variables null since they automatically are destroyed after all have been send right?
I don't have much experience in memory management so that's why i ask, if anyone has a good link for me to some Java memory management site I would be thankful.
Thanks
[804 byte] By [
radicjesa] at [2007-11-27 0:50:22]

> public void createUser( User user )
> {
> ...this.user = user;
> ...ormapper.start();
> ...ormapper.save(this.user);
> ...ormapper.end();
> ...this.user = null;
> }
Actually there is no need to use this.user at all.
public void createUser( User user )
{
ormapper.start();
ormapper.save(user);
ormapper.end();
}
In general if you put a variable to null, it can be gc'd, but there is no guarantee that it happens! If you apply it to a class member however, I am not sure if it is even eligible for garbage collection before the containing object is destroyed!
> When i call this function, does it matter if i make
> this.user null ?
No, it doesn't.
> Also, on a webpage, is it usefull to make variables
> null
Not really.
>
> I don't have much experience in memory management so
> that's why i ask, if anyone has a good link for me to
> some Java memory management site I would be
> thankful.
There are very few cases where explicit nulling of variables helps.
Most of those cases have to do with incorrect scoping ( i.e. an object is scoped more broadly than the use of that object).
Maybe this [url=http://www-128.ibm.com/developerworks/library/j-jtp01274.html]article[/url] can help. See the "Explicit nulling" paragraph.