Solved

inner class memory leaks

Posted on 2013-01-24
2
539 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

730 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