From: Arno P. <ar...@pu...> - 2011-01-21 19:46:54
|
On 1/21/11 11:40 AM, Panayotis Katsaloulis wrote: > > On Jan 21, 2011, at 6:31 PM, Arno Puder wrote: > >> he Objective-C backend still relies on >> reference counting and it happens *very* quickly that your application >> contains a cycle in the data structure and therefore leaks memory. These >> are just two things where the new backend is superior. > > > I have a question with the GC. > > There are some selectors in iOS which return an autoreleased object. This is not really the problem. > The problem is if this object is released later on, for example after an animation cycle. > I can't think right now of a working test example, but I'd like to hear how well the GC behaves in such mixed situations. As an example, here is how it is done for [UIButton buttonWithType:...]: JAVA_OBJECT org_xmlvm_iphone_UIButton_buttonWithType___int(JAVA_INT n1) { if (!__TIB_org_xmlvm_iphone_UIButton.classInitialized) __INIT_org_xmlvm_iphone_UIButton(); //XMLVM_BEGIN_WRAPPER[org_xmlvm_iphone_UIButton_buttonWithType___int] NSAutoreleasePool* p = [[NSAutoreleasePool alloc] init]; UIButton* objcBtn = [UIButton buttonWithType: (UIButtonType) n1]; [objcBtn retain]; [p release]; JAVA_OBJECT b = __NEW_org_xmlvm_iphone_UIButton(); org_xmlvm_iphone_UIControl_INTERNAL_CONSTRUCTOR(b, objcBtn); return b; //XMLVM_END_WRAPPER } You are right: so-called convenience methods in Cocoa place the newly-created object automatically in the autorelease pool. You can see above that we create a temporary autorelease pool that we release again immediately. When the GC reclaims the C version of UIButton, it will call a finalizer (the __DELETE_* functions) that will do a 'release' in the wrapped Objective-C UIButton. Arno |