• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Accessor methods and (auto)release <Memory trail>
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: Accessor methods and (auto)release <Memory trail>
  • From: David Newberry <email@hidden>
  • Date: Wed, 31 Jul 2002 04:31:10 -0700

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.

  • Prev by Date: Re: NSImageRep.imageFileTypes() doesnt work...
  • Next by Date: PDF generation bug? w/ attachment
  • Previous by thread: Re: Accessor methods and (auto)release <Memory trail>
  • Next by thread: Re: Accessor methods and (auto)release <Memory trail>
  • Index(es):
    • Date
    • Thread