From: Paul P. <bay...@gm...> - 2012-02-24 16:41:42
|
In Java, a *static* inner class is just a fancy way to make another class, but a non-static inner class maintains an implied strong reference to the containing instance. In code, it is also available via "ContainingClass.this". For example, assume class A contains inner class B which contains inner class C. If B & C are static classes, they will not have access to the containing class' non-static variables. If B & C are NOT static, B maintains a strong reference to A, and C maintains a strong reference to B. In your scenario, A now has references to C, but has removed all references to B. As long as there is a non-collectible reference to A and as long as A references C, B will not be collected, since C references B. So to answer your questions directly: 1) Yes 2) The non-static inner class has a strong reference to the containing class Thanks, Paul On Fri, Feb 24, 2012 at 7:31 AM, Panayotis Katsaloulis < pan...@pa...> wrote: > Is it possible to give me some hints, how the GC is working with inner > classes? > > I have this scenario: > > A class (level 0) has an anonymous inner class (level 1) , which in turn > has inside another anonymous inner class (level 2). > > The lifetime is like this: > > i) Class of level 0, creates a level 1 class > ii) Level 1 class creates level 2 class and gives its reference back to > level 0 class > iii Level 0 class removes all usage & references of level 1 class (the > item should be released) > iv) Level 2 class starts executing, while requiring some variables of > level 0 class. > > If I am correct, currently XMLVM is able to access information of level 0 > class to the level 2 class through the level 1 class. > If this is so, a segmentation fault would appear. > > > 1) Is this situation handled correctly by the C backend? > > 2) In ObjC backend, I can see that the inner classes hold a weak reference > to the parent class. What if we establish a strong reference between the > parent and the inner class ? > > > > > ------------------------------------------------------------------------------ > Virtualization & Cloud Management Using Capacity Planning > Cloud computing makes use of virtualization - but cloud computing > also focuses on allowing computing to be delivered as a service. > http://www.accelacomm.com/jaw/sfnl/114/51521223/ > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > |