Re: [Pyobjc-dev] memory management.
Brought to you by:
ronaldoussoren
|
From: Ronald O. <ous...@ci...> - 2002-10-28 08:51:51
|
Jonathan,
I agree that we should try to abstract away manual management of
reference counts. Until a few days ago I believed we already reached
this point.
There are now two sets of ...
1. Bill mentioned that it is common in some Objective-C code to transfer
ownership of returned objects to the caller (He's the resident expert
on these issues, I'm learning Objective-C/Cocoa as a go along).
It will be hard to correctly identify all these cases. IMHO this
shouldn't
keep us from doing away with autorelease/release/retain in Python
code:
it will just be a little harder to correctly wrap an Objective-C
class
library. As wrapping an Objective-C class is an order of magnitude
simpler
than wrapper other 'native' code that should not be a problem.
2. Bill also mentioned a coding style that uses 'autorelease' to make
sure
that an object is around to the end of the current loop through the
eventloop (which in case of non-GUI programs may be quite a long
time).
I don't really like this coding style, so IMHO it is not a problem
to use
'obj.retain().autorelease()' in these cases, instead of just
'obj.autorelease()'. I'm also pretty sure that doesn't really have
anything
to do with the automatic management of refcounts by the bridge.
3. The NSMutableArray class cluster (and probably all NS<DataStructure>
class
clusters) play games with reference counts during allocation. This
is not
a problem if you use the common Objective-C idiom, but it is when
you try
to automate management of reference counts.
Basicly the issue is that the Objective-C manual strongly suggest
that the
following two lines should be equivalent, but they are not for these
class
clusters:
NSArray.alloc().autorelease().init() # Basicly what the bridge does
NSArray.alloc().init().autorelease() # Common Objective-C idiom
I'm thinking on how to fix this. The one requireing the least amount
of
engeneering is saying "Don't use 'alloc().init()' for these class
clusters",
or even "Don't allocate Objective-C containers from Python". I don't
really
like this and am thinking on how to fix this in a correct manner.
Ronald
|