Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessor methods and (auto)release <Memory trail>



Perhaps a pointless email, but if you'll humor me...

- (void) setTheory:(Theory *)newTheory {
if (theory == newTheory) return;

I would not do that for the reasons above. If you have reasons to believe
that theory==newTheory would occur often though, it might bring some -- in
my estimate *utterly* unimportant and invisible -- speedup.
...

[theory release];
theory = [newtheory copy/retain];
}

Alas, not only simple, but also incorrect in the case theory==newTheory &
&
[theory retainCount]==1. If so, the release would *dealloc* the object,
and thus the subsequent retain/copy sent to the same object would crash
(or, with a multithreaded app, do even worse things).

This criticism seems based on a faulty assumption. In the context of the code presented in the question, the case you site has already been accounted for. The code presented may be slowed down slightly if theory most often != newTheory, but it's certainly not incorrect code in any way,
and assuming average conditions (say theory will sometimes be equal to newTheory), you will get fine speed. In any other situation, it seems like a debate between what causes more lag, autoreleasing and the test presented above.

Just a thought. Perhaps I should leave these things to the pros, but I just thought I'd toss it in. :)

Peace,
-David Newberry
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.