• 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
Does an enumerator retain the last object?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Does an enumerator retain the last object?


  • Subject: Does an enumerator retain the last object?
  • From: zauhar <email@hidden>
  • Date: Mon, 1 Dec 2003 09:21:29 -0500

This is a weird thing I bumped into. Here is my dealloc method for a
tree. Each node of the tree points to other nodes, so before releasing
the nodes I first release the array of connections that each node
maintains to point to its neighbors:

- (void) dealloc
{
NSEnumerator *nodeEnumerator ;
SMILESNode *nextNode ;

nodeEnumerator = [ nodes objectEnumerator ] ;

while( ( nextNode = [ nodeEnumerator nextObject ] ) )
{
[ [ nextNode connectNodes ] release ] ;
}

[ nodes release ] ;

[ super dealloc ] ;

return ;
}

While debugging, I noticed that upon exiting the while loop the retain
count of the LAST node was increased by one. I looked in other places
in my code where I use enumerators, and this seems always to be the
case.

When I release the local autorelease pool, the last node is released (I
assume because the enumerator is released), so the method works.
However I am puzzled by this - while I can understand why the whole
collection is retained while enumerating, what is the point of
retaining the very last item enumerated? The retain count of items
prior to the last does not seem to be increased.

Am I missing something obvious? Am I nuts? I could find nothing in the
archives about this.

Thanks!

Randy

Randy J. Zauhar, PhD
Assoc. Prof. of Biochemistry
Director, Graduate Program in Bioinformatics
Dept. of Chemistry & Biochemistry
University of the Sciences in Philadelphia
600 S. 43rd Street
Philadelphia, PA 19104

Phone: (215)596-8691
FAX: (215)596-8543
E-mail: email@hidden
Web: http://tonga.usip.edu/zauhar


Discussion after watching Disney's "Lilo & Stitch":

DAD: "But why did the space aliens speak English, as opposed to French,
or Swahili? And why did the one alien speak English with an Eastern
European accent? I don't get it."

CATHERINE (age 7): "That's 'cause you don't have a good cartoon brain."
_______________________________________________
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: MutableArrays losing its contents?
  • Next by Date: Re: Catching mouse-clicks outside UI elements
  • Previous by thread: Re: Catching mouse-clicks outside UI elements
  • Next by thread: Re: rounding a float
  • Index(es):
    • Date
    • Thread