Re: [Pyobjc-dev] Memory management bug using .new() -- and another one?
Brought to you by:
ronaldoussoren
From: Dirk S. <dir...@ma...> - 2009-06-19 10:06:23
|
Hi Ronald, Thanks for the clarification. :) I found another weird memory management quirk that might be related. Summary: Objects that implement the designated initializer are not automatically released as top-level objects in nibs owned by view- and windowcontrollers. Example: I have the following two classes: ---------------- class SFTestViewVanilla(NSView): def dealloc(self): NSLog(u'yay, dealloc in %s' % self) super(SFTestViewVanilla, self).dealloc() class SFTestViewWithInit(NSView): def initWithFrame_(self, frame): NSLog(u'initWithFrame_ called in %s' % self) self = super(SFTestViewWithInit, self).initWithFrame_(frame) if self: pass return self def dealloc(self): NSLog(u'yay, dealloc in %s' % self) super(SFTestViewWithInit, self).dealloc() ---------------- Instances of each of these have been put as top-level objects in a nib file that's owned by an NSViewController subclass. Actually, to be entire correct, I dragged in 'custom views' and set the class of one of them to SFTestViewVanilla, and another one to SFTestViewWithInit. So those custom view placeholders are replaced with my custom subclasses when the nib is loaded, causing initWithFrame: to be called on both of them. When the CHViewController is released, the SFTestViewVanilla instance is deallocced and produces a log entry, the SFTestViewWithInit instance however, is not being deallocced. The only difference between both is the implementation of them pasted above. More Testing: I've also tried not assigning to self in SFTestViewWithInit's initWithFrame: implementation but that makes no difference whatsover. As a next step of figuring stuff out: If I set up outlets to each, and check their retainCount in awakeFromNib, they both start out with a retainCount of 1. Initially I suspected that there's something weird going on with NSViewController's memory management of its top-level objects, if those objects are implemented in Python. This weirdness however only happens with objects that implement the designated initializer. Next I've added these same views as top-level objects in a different nib that's owned by an NSWindowController subclass, where they exhibit the exact same behavior. In both cases there are no outlets to the views (just added those at some point to look at retainCounts for additional clues) and the views aren't part of any view hierarchy. The same seems to happen with other objects that have their own init, like my NSArrayController subclass and other things that don't inherit from NSView. (I have not isolated that behavior yet, but from my app's code I suspect this is going on) Right now, I'm special casing every viewController's and windowController's dealloc to manually release these views, but I completely fail to understand why something is going haywire with the 'automatic' releasing of top-level objects that NSViewController and NSWindowController are supposed to do.. This seems to be a bug, that I'd rather fix in one spot than work around everywhere. I'd love to look into this and fix it myself, write a regression test, and submit a patch. Could you help me out with some pointers on where to start looking in the PyObjC source? Thanks! - Dirk PS: I'm using pyobjc_core-2.2b2-py2.5, installed from a downloaded .tar from pypi.python.org, because installing from trunk didn't work out on my machine (10.5.7) On Jun 19, 2009, at 10:47 AM, Ronald Oussoren wrote: > > On 18 Jun, 2009, at 22:47, Orestis Markou wrote: > >> Hi Ronald, >> >> does that stand for other arbitrary class methods, like CALayer.layer >> () as well? Is there a way to inform PyObjC of constructor class >> methods? Or should we change our code to use alloc().init() instead? > > No. The only class methods that behave like alloc are alloc itself > and anything that starts with 'new'. Regular class methods return > autoreleased objects. > > The behaviour of method names that start with 'new' is newish, the > last time I check (which was a couple of years ago), only +alloc > returned a retained value. > > Ronald > > > ------------------------------------------------------------------------------ > Crystal Reports - New Free Runtime and 30 Day Trial > Check out the new simplified licensing option that enables unlimited > royalty-free distribution of the report engine for externally facing > server and web deployment. > http://p.sf.net/sfu/businessobjects > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |