After learning about the inner class, I understand it has an implicit reference to the outer class.
But my teacher told me that the best way is not use inner class, prefer to use static inner class. Because the inner class may leak memory.
Can someone kindly explain about this?
In the answer to your comment (it would be unreadable if I posted it in the comments), where it belongs. Example of accesing inner class outside the outer.
somewhere else in your code
So you don't need to access the inner class through its parrent class, once the inner object is created it can be used as any other object and can be 'leaked outside' its container class, like in the above example, when the dog list will hold references to dogs, but each dog will still 'know' about its kennel.
The linked example from StackTrace was related to typical use case, when the innner classes are created 'ad hock' as anonymous inner classes, but it is the same problem. If you pass the reference to any instance of an inner class, you are also 'passing' reference to the outer class.