Meaning of Objects Retained by Inner Class Back References

Questions about YourKit Java Profiler
Post Reply
avi
Posts: 7
Joined: Sun Nov 19, 2017 10:32 am

Meaning of Objects Retained by Inner Class Back References

Post by avi »

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 ?
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Meaning of Objects Retained by Inner Class Back Referenc

Post by Anton Katilin »

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.
avi
Posts: 7
Joined: Sun Nov 19, 2017 10:32 am

Re: Meaning of Objects Retained by Inner Class Back Referenc

Post by avi »

thank you. very helpfull
Post Reply