Re: [Pyobjc-dev] Memory Management Problem - Objects being deallocated
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2009-09-29 20:29:43
|
On 29 Sep, 2009, at 22:09, Lukas Pitschl | Dressy Vagabonds wrote: > A different question, would it negatively affect to plugin if I used > retain, > wherever the original objective-c code uses it? That should work if you call release or autorelease as well, and if you ignore that some ObjC methods (such as +alloc and -copy) return an object with a +1 retainCount because PyObjC automaticly compensates for that. That is, the following code is invalid in PyObjC, but the corresponding ObjC code is correct: a = NSArray.alloc().init() a.release() a = None As James noted manually managing the retaincount shouldn't be necessary in most code, except that some ObjC APIs use ObjC-style weak references and you must ensure that objects you pass to those APIs stay alive. The most visible of those are notification centers and objects returned by the outlineview dataprovider protocol. Ronald > > Lukas > > > Am 29.09.2009 um 19:28 schrieb James R Eagan: > >> Hi Lukas, >> >> Most likely PyObjC is doing the right thing, just not what you >> expect. I suppose it depends on your definition of the right thing, >> though. It's hard to say what's happening based on what you've >> given, but it sounds like you might have a case of unretained >> delegates. >> >> PyObjC will hold an ObjC reference (i.e. retain) any objects on its >> side of the bridge. Remember that for some Cocoa delegates and data >> providers, you are expected to retain a copy of the data source >> (e.g. NSTableView dataSource). If you don't make sure you keep a >> python reference to that object, then PyObjC will no longer keep the >> ObjC reference, and the object will be released. So the first place >> I'd look is to make sure you're keeping a python reference to all >> your dataSource's and other appropriate delegates (the Cocoa >> documentation is your friend here). >> >> Good luck! >> James >> >> On 29 sept. 2009, at 18:34, Lukas Pitschl | Dressy Vagabonds wrote: >> >>> At the moment I'm re-implementing the GPGMail Plugin in PyObjC and I >>> noticed >>> that sometimes the Mail.app crashes because PyObjC is accessing >>> memory >>> that >>> is no longer allocated. >>> >>> As the documentation mentions memory management should be left to >>> PyObjC >>> I wonder how this can happen. >>> >>> Should i use retain on the object? Any suggestions how to find the >>> objects that are causing the problem >>> or debug this situation further? >>> >>> Greets >>> >>> Lukas >>> >>> ------------------------------------------------------------------------------ >>> Come build with us! The BlackBerry® Developer Conference in SF, >>> CA >>> is the only developer event you need to attend this year. Jumpstart >>> your >>> developing skills, take BlackBerry mobile applications to market >>> and stay >>> ahead of the curve. Join us from November 9-12, 2009. Register >>> now! >>> http://p.sf.net/sfu/devconf >>> _______________________________________________ >>> Pyobjc-dev mailing list >>> Pyo...@li... >>> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev >> > > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry® Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart > your > developing skills, take BlackBerry mobile applications to market and > stay > ahead of the curve. Join us from November 9-12, 2009. Register > now! > http://p.sf.net/sfu/devconf > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |