Re: Fast Enumeration and temporary objects/autoreleasing
Re: Fast Enumeration and temporary objects/autoreleasing
- Subject: Re: Fast Enumeration and temporary objects/autoreleasing
- From: Graham Cox <email@hidden>
- Date: Tue, 17 Apr 2012 10:10:44 +1000
While you have had the question answered, the fact you asked it shows a misunderstanding about memory management.
How fast enumeration is implemented should not make any difference to you, as its user. If it did create temporary objects then it would be responsible for clearing them up. (But then again, if it did, it probably wouldn't deserve its name).
Memory management is really quite straightforward, and consists of a few rules that everything follows (the framework invariably does; your code should do). People do tie themselves in knots trying to second-guess what is "really" going on, but you just need to learn the rules and it all becomes pretty simple.
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html
--Graham
On 16/04/2012, at 7:42 PM, Patrick Robertson wrote:
> Hi all,
>
> I've searched the web, but can't seem to find any concrete information on
> how fast enumeration loops manage temporarily created objects.
> Would anybody be able to shine some light on whether fast enumeration
> itself takes care of the objects it creates?
>
> So, for example in:
>
> for (id anObject in anArray) {
> // do some stuff
> }
>
> I'm assuming that the fast enumeration loop itself does something like this
> behind the scenes for each object in the array:
> id anObject = [anArray objectAtIndex:i]
>
> so are these temp objects created during the enumeration released
> automatically at the end of the loop, or is it work wrapping the whole
> thing in an autoreleasepool?
>
> @autoreleasepool {
> for (id anObject in anArray) {
> // do some stuff
> }
> }
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden