Solved

inner class memory leaks

Posted on 2013-01-24
2
533 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
couple of eclipse 5 46
servlet web applications   metadata-complete="true" or false 3 109
jmss example java 2 23
Java program running SQL query 5 37
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

808 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