Solved

inner class memory leaks

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
micro services vs rest web services 16 103
web application structure 18 76
Java exception bubble up 2 17
hibernate example for saving data 19 37
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

813 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

12 Experts available now in Live!

Get 1:1 Help Now