Re: [Pyobjc-dev] Memory problems with PyObjC and outlets in nibs
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2006-09-15 08:12:33
|
On Friday, September 15, 2006, at 08:20AM, Josh Marshall <jos...@gm...> wrote: >For a while now, I've been perplexed with strange memory crashes >involving several PyObjC applications. They were occurring when >windows were closed and it seemed that objects were getting released >multiple times. > >I couldn't find any resources on debugging these crashes, and turned >to see if there was anything similar on the Objective C side of >things. I found this: http://www.cocoadev.com/index.pl? >DebuggingAutorelease which explains the NSDebugEnabled, >NSZombieEnabled, MallocStackLogging environment variables. > >Setting these, I immediately found the source of the error. I have >AIDocument and AIWindowController subclasses (their superclasses >should be obvious) in Python, also defined in my Document nib. The >nib has an NSImageView in the window and the AIWindowController has a >"plotView" outlet connected to it. > >Now when I close the window, the NSImageView gets released once too >often. I'm guessing that once is when the File's Owner (in this case >AIWindowController) is dealloced, and the other when the nib >structure itself is dealloced, but this is conjecture. > >This same problem has occurred to me elsewhere. It seems that if an >object is assigned to an outlet in a nib, it seems to need a retain >called on the outlet after the nib has finished loading. I couldn't >find anywhere that this was documented, and so my question is if this >is expected behaviour or a bug? > >My other question is whether there is any way to get a C stack trace >from within the Python code? I eventually tracked this bug down by >overriding retain and release on my Python ObjC objects and >displaying the retain count, but it would be very handy to know where >my Python-defined methods are being called from. I tried running gdb >during a pdb.set_trace(), but this just caused mayhem. Are there any >good resources on debugging PyObjC apps? Not really. I usually use a combination of pdb and (mostly) gdb to hunt down issues like this one. Could you create a small project that demonstrates the problem? From your description I'd say this is a bug in PyObjC, but not one I've run into before. Ronald |