Re: [Pyobjc-dev] Memory management bug using .new()
Brought to you by:
ronaldoussoren
From: Orestis M. <or...@or...> - 2009-06-18 19:49:36
|
That's interesting, we are seeing similar behaviour to other classmethods that do this (eg. CALayer.layer()), but so far I chalked it up to our fault. Perhaps it's the same issue? Orestis On 18 Jun 2009, at 16:54, Dirk Stoop wrote: > Hi all, > > I don't think anyone ever uses this method – NSObject.new() – anymore, > but in case someone does: I just ran into a reproducable problem with > it. > > When you create a new cocoa object within an instance method of a > Cocoa class implemented in Python, normally that fresh object is > released when the scope dissapears. (that is, when you're not storing > a reference to it in an attribute that exists outside of the method's > scope). > > e.g.: > > class MyAmazingViewController(NSViewController): > def animate(self): > animation = NSViewAnimation.alloc().init() > # insert code to create an array/list of NSDictionaries > describing the animations > > animation.setViewAnimations_(theAboveMentionedHypotheticalArray) > animation.setDuration_(5.0) > animation.setAnimationBlockingMode_(NSAnimationNonblocking) > animation.startAnimation() > > ( if the spaces got stripped from my example somehow, snippet also > pasted here: http://pastie.org/516369 ) > > After control returns from the "animate" method, and after the > animation is done, it is automatically released. > > However if you replace "NSViewAnimation.alloc().init()", with > "NSViewAnimation.new()", the animation is not automatically released. > Consequentially, any views or windows included in the dictionaries > that form the viewAnimations array are also retained, causing quite a > significant leak. > > Juding from the NSObject class docs, calling "new()" on a class should > do exactly the same thing as "alloc().init()", but PyObjC doesn't seem > to treat it the same way. > > http://tinyurl.com/nsobject-new > > Can anyone enlighten me whether this is a bug, a feature, or simply > something I'm misunderstanding? > > Thanks! > - Dirk > ------------------------------------------------------------------------------ > 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 |