Re: [Pyobjc-dev] Headache over hacking an XML editor
Brought to you by:
ronaldoussoren
From: Just v. R. <ju...@le...> - 2003-01-14 16:51:16
|
bb...@ma... wrote: > On Tuesday, Jan 14, 2003, at 05:00 US/Eastern, Just van Rossum wrote: > > Hm, I just discovered .release() returns None. If I do the > > release() separately it works just fine. I still don't understand > > why cls.alloc().init() would result in a retainCount of 2, though. > > Every time I see a retain() or release() call in Python code I > > can't help but think there's something terribly wrong :-( > > It has to do with the way the retain/release mechanism works. In > any case, you have one -retain for alloc() and one for the assignment > in python. Why? The caller of alloc() becomes the owner, and I don't see why the Python wrapper *wouldn't* become the owner. > I agree that it would be very, very nice NOT to have to ever deal > with retain/release/autorelease on the Python side of the PyObjC > bridge. Unfortunately, it appears to be impossible [AFAICT] to > automate the management of retain/release/autorelease with 100% > reliability. Anything that makes assumptions regarding retain counts > and adjusts the count downwards automatically will lead to situations > where the app blows up. I don't see why it's a bad "assumption" that the Python wrapper becomes the owner of the reference, IMHO it's only natural. I've tried to read the implementation (class-object.m) but I can't follow it at all because of the complexity. I seem to see that it attempts to synchronize the objc retainCount and the Python ob_refcnt. Why is that? I would think the Python wrapper for an objc object only needs to own one reference and vice versa for an objc wrapper for a Python object. I'm sure I'm missing something subtle, but now is as good a time to learn about how it works as any ;-) When creating a Python wrapper, there should be a difference between "wrap an existing ref" and "wrap a new ref". > Ronald and I discussed this at length some time ago-- I believe it > was before you had become active on the project. There is actually > code to maintain the release counts automatically, it is currently > commented out. Check the archives for more information.... I searched, to no avail. Any specific pointers or google keywords? Just |