On 24 May 2012, at 16:27, Kyle Sluder wrote:
>> 1. If I do not set B's pointer to A, both A and B are deallocated correctly
>> 2. If instead I set B's pointer to A, but reset it to nil just before B is 
>> closed, both A and B are deallocated correctly
>> 3. If instead B still has a live pointer to A when B is closed, this should 
>> be autoreleased by the runtime, which it is. However, A never gets 
>> deallocated.
> 
> If A somehow has a chain of retains that keeps B alive, #3 is wrong. Your 
> approach with #2 seems sensible.

Thankyou all three for your replies. [I am not using ARC as this must run on 
Snow Leopard, incidentally].

Having done some playing around with trivial test cases, it appears that I have 
completely misunderstood a basic concept of properties - apologies for wasting 
your time. I had always thought that if I declare a property as follows:

@property (retain) MyProgressWindow * progressObject;
...
@synthesize progressObject = _progressObject;

then if that property has a non-nil value at the point that the instance is 
deallocated, a release would be sent. That had always struck me as the 
"obvious" behaviour, but it appears that this does not happen. I am sure there 
is a good reason for that! Not sure how I have managed to go this long without 
spotting that I am wrong here. Seems a bit of a pain to have to go through 
setting everything to nil in the dealloc method (which I would otherwise not 
have to even implement at all in many cases), but looks like that's what I need 
to do...

Cheers
Jonny
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to