Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method local inner class

 
Asanka Vithanage
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if we create a method local inner class object
Is it eligible for garbage collection after method completion.?
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, until you pass this object reference outside the method.
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you create a Method Local Inner class, it is NOT eligible for garbage collection. If you create an instance of the Method Local Inner class, that will be eligible for GC after the method call returns. But there is a twist here. You cannot declare a method local inner class as return type of a method. So you have to use a base type of the method local inner class as the return type of the method.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic