Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-19-2011, 07:17 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 1
Aranir is on a distinguished road
Question Simple enumerator Question

Greetins I'm starting objectiv C and while reading a book I stubled upon the following example:

1 NSMutableArray *displayList = ... // Array of graphic objects
2 GraphicObject *graphicObject;
3
4 NSEnumerator *enumerator =
5 [[NSArray arrayWithArray: displayList] objectEnumerator];
6
7 while ( graphicObject = [enumerator nextObject] )
8 {
9 if ( [graphicObject isBitmap] )
10 {
11 [displayList removeObject: graphicObject];
12 }
13 }

AS I understand to create the NSEnumerator *enumerator, we create a new NSArray with the displayList and create an objectEnumerator from that.

Now my problem is, how do I release the NSArray afterward which was created? as I don't see to have a direct reference to it, but only the object enumerator created from it.

I'm completely new so maybe I miss something how memory is managed in Objective C.


Any advice on this subject would be greatly appreciated.
Aranir is offline   Reply With Quote
Old 05-08-2011, 05:34 PM   #2 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 66
Sami Gh is on a distinguished road
Default

You don't need to release it. arrayWithArray method creates an autoreleased object, so it is the responsibility of the pool to release the object.
However, if you create the array using alloc/initWithArray then you can do it in two steps so you can keep the pointer to the array to release it.


Quote:
Originally Posted by Aranir View Post
Greetins I'm starting objectiv C and while reading a book I stubled upon the following example:

1 NSMutableArray *displayList = ... // Array of graphic objects
2 GraphicObject *graphicObject;
3
4 NSEnumerator *enumerator =
5 [[NSArray arrayWithArray: displayList] objectEnumerator];
6
7 while ( graphicObject = [enumerator nextObject] )
8 {
9 if ( [graphicObject isBitmap] )
10 {
11 [displayList removeObject: graphicObject];
12 }
13 }

AS I understand to create the NSEnumerator *enumerator, we create a new NSArray with the displayList and create an objectEnumerator from that.

Now my problem is, how do I release the NSArray afterward which was created? as I don't see to have a direct reference to it, but only the object enumerator created from it.

I'm completely new so maybe I miss something how memory is managed in Objective C.


Any advice on this subject would be greatly appreciated.
__________________
Sami Gh is offline   Reply With Quote
Old 05-12-2011, 02:28 AM   #3 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 36
cncool is on a distinguished road
Default

Quote:
Originally Posted by Aranir View Post
Greetins I'm starting objectiv C and while reading a book I stubled upon the following example:

1 NSMutableArray *displayList = ... // Array of graphic objects
2 GraphicObject *graphicObject;
3
4 NSEnumerator *enumerator =
5 [[NSArray arrayWithArray: displayList] objectEnumerator];
6
7 while ( graphicObject = [enumerator nextObject] )
8 {
9 if ( [graphicObject isBitmap] )
10 {
11 [displayList removeObject: graphicObject];
12 }
13 }

AS I understand to create the NSEnumerator *enumerator, we create a new NSArray with the displayList and create an objectEnumerator from that.

Now my problem is, how do I release the NSArray afterward which was created? as I don't see to have a direct reference to it, but only the object enumerator created from it.

I'm completely new so maybe I miss something how memory is managed in Objective C.


Any advice on this subject would be greatly appreciated.
Just do this:

for(GraphicObject * graphicObject in displayList)
{
//use graphicObject
}
cncool is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 481
15 members and 466 guests
7twenty7, AlanFloyd, AppsBlogger, David-T, iAppDeveloper, imac74, Jaxen66, lovoyl, Music Man, mutantskin, Paul Slocum, SLIC, solardrift, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,683
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, unicornleo
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:13 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0