• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can we make a final variable eligible for garbage collecion  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it possible to make a final class level variable eligible for garbagge collector explicitly.

if mean how?

Regards
Siva
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Why do you want to know whether a reference is or is not eligible for garbage collection? The whole idea of a high-level language is that you let the JVM worry about such details.

It will only be unreachable when there are no references to its surrounding object.
 
shiva murugan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell Ritchie ,

Thanks for your quick reply, my point is, i have a final variable pointing to a object, how do i make that particular object eligible for garbage collection

Regards
Siva
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the variable is static you can't because you'll always have an accessible reference to that object.
If not then just make then surrounding instance eligible for gc.
 
shiva murugan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouter Oet wrote:If the variable is static you can't because you'll always have an accessible reference to that object.
If not then just make then surrounding instance eligible for gc.



Actually in my case i am creating a filter class and it uses, and i had defined the logger as a final instance variable, under this circumstances, in the destroy method of the filter class i wish to explicity free the logger resource.

is this possible?

 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Destroy method? Do you mean finalize()? If so then you don't need to worry about a thing. When the outer object is garbage collected the logger will be garbage collected as well.

If you really need to change the reference to null then you have no option but to drop the final keyword.
 
shiva murugan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, i got some good replies for my first post.

Also it is not finalize, it is destroy method of the filter servlet, that is responsible of releasing all the resources held by it

Regards
Siva
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah right. That destroy method.

Then my final sentence is the definite answer: if you want to null it it cannot be final.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!