Fully featured low overhead profiler for Java EE and Java SE platforms.
Ultimate profiling and monitoring solution for Gradle, Maven, Ant, JUnit and TestNG.
Easy to use performance and memory profiler for .NET framework.

Meaning of Objects Retained by Inner Class Back References

Moderators: Vladimir Kondratyev, Anton Katilin

Meaning of Objects Retained by Inner Class Back References

Postby avi » Wed Jan 10, 2018 7:49 am

Newbi using yourkit. What does it mean :
Objects Retained by Inner Class Back References
Find objects retained via synthetic back reference of its inner classes.
Problem: Such objects are potential memory leaks.

can you explain with simple example ?
we have some suspicious leaks in our app. does it matter if it scala/akka app ?
avi
 
Posts: 7
Joined: Sun Nov 19, 2017 10:32 am

Re: Meaning of Objects Retained by Inner Class Back Referenc

Postby Anton Katilin » Wed Jan 10, 2018 9:10 am

Each non-static inner class instance has a reference to the outer class instance from which it was created.

As long as you keep a reference to such inner class instance, its creator object, the outer class instance, will be kept in memory too. In some cases this is undesirable, thus causes the outer class instance leak. Such cases are hard to find manually, without using this inspection.

Consider example:
interface Foo {}

class FooBuilder {

// inner non-static class implementing Foo, has reference to FooBuilder
class FooImpl implements Foo {}

Foo createFoo() {
return new FooImpl();
}
}


As long as you keep references to Foo instances created with FooBuilder, you'll keep the builder objects in memory too. If the builder's purpose is solely to create a Foo and then be thrown away, this creates a leak.

Of course, there are legitimate cases when such retention is desired. The inspection mechanically shows all cases, and it's up to the analyst to decide on each particular reported case.
Anton Katilin
 
Posts: 5649
Joined: Wed Aug 11, 2004 8:37 am

Re: Meaning of Objects Retained by Inner Class Back Referenc

Postby avi » Thu Jan 11, 2018 10:38 pm

thank you. very helpfull
avi
 
Posts: 7
Joined: Sun Nov 19, 2017 10:32 am


Return to Java Profiler

Who is online

Users browsing this forum: No registered users and 19 guests

cron