• 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: 9597
36
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.

 
We begin by testing your absorbancy by exposing you to this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!