How inner class object resides in memory?

后端 未结 3 1714
一向
一向 2020-12-15 01:41

Outer outer = new Outer();

an Object of Outer class is created on heap and reference variable points to it.

If I under

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 02:10

    Each instance of an inner class holds a reference to an instance of its outer class. It's the reference that you get when you write Outer.this within one of the inner class's methods. The anonymous Outer instance won't be eligible for garbage collection unless all Inner instances associated with it are also eligible for garbage collection.

提交回复
热议问题