Solved

inner class memory leaks

Posted on 2013-01-24
2
521 Views
Last Modified: 2013-01-25
hi all
<<<Non static inner classes can result in memory leaks while static inner class will protect against them. If the outer class holds considerable data, it can lower the performance of the application. >>

Is the above statement true? Can someone please explain with example?

thanks
0
Comment
Question by:royjayd
2 Comments
 
LVL 4

Accepted Solution

by:
tvedtem earned 500 total points
ID: 38816850
The reason for this statement is that such classes hold an implicit reference to their parent.

This doesn't necessarily cause a memory leak.

What it means is that if you create an instance of a non-static inner class, an instance of the enclosing class will also be created.

It follows that if you create an instance of an inner class from somewhere else, you are effectively keeping a reference the enclosing class, for as long as the inner class is alive.

If the enclosing class contains something large, you can 'leak' a large amount of memory without realising (since you don't realise you are keeping an instance of the enclosing class alive alongside the inner class).

In practice all you really need to do is be careful when constructing an instance of an inner class.
0
 
LVL 16

Expert Comment

by:Valeri
ID: 38818868
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now