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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-20-2010, 08:18 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 109
freedoom is on a distinguished road
Default iPhone memory managment

I read this article.
10 iPhone Memory Management Tips | akosma software

This statement is still relevant today?
Particularly this:
"Autoreleasing objects is easy and useful, but on the iPhone you should be careful with it. By default there is an NSAutoreleasePool instance created for you at the beginning of the main() function but this pool is not cleared up until your application quits!
I started getting a better performance from my iPhone apps when I stopped using some methods creating autoreleased objects, for example:

// Instead of
NSString *string = [NSString stringWithFormat:@"value = %d", intVariable];

// use
NSString *string = [[NSString alloc] initWithFormat:@"value = %d", intVariable];
...
[string release];"

Thanks for your attention
freedoom is offline   Reply With Quote
Old 09-20-2010, 08:22 AM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

As performance improves and the devices get more RAM, it becomes less relevant. So the iPhone 4 isn't too bad. But the iPad is almost as bad as the original iPhone, so there is still some relevance to the sentiment.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 09-20-2010, 08:24 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

Taken from Loading… :
"The Application Kit automatically creates a pool at the beginning of an event cycle (or event-loop iteration), such as a mouse down event, and releases it at the end, so your code normally does not have to worry about them. There are three cases, though, where you might use your own autorelease pools:

*If you are writing a program that is not based on the Application Kit, such as a command-line tool, there is no built-in support for autorelease pools; you must create them yourself.
*If you spawn a secondary thread, you must create your own autorelease pool as soon as the thread begins executing; otherwise, you will leak objects. (See “Autorelease Pools and Threads” for details.)
*If you write a loop that creates many temporary objects, you may create an autorelease pool inside the loop to dispose of those objects before the next iteration. This can help reduce the maximum memory footprint of the application.

Autorelease pools are used “in line.” There should typically be no reason why you should make an autorelease pool an instance variable of an object."

So yes and no, there is a default autorelease pool and it gets empyty (create also) with in the event loop.
TUX2K is offline   Reply With Quote
Old 09-20-2010, 08:31 AM   #4 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 109
freedoom is on a distinguished road
Default

Thanks!
In my app I have more mapView annotation.
In the cycle ( when I initialize the annotation ) can I
create the autorelease pool for optimize the performance?
freedoom is offline   Reply With Quote
Old 09-20-2010, 09:01 AM   #5 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Edinburgh
Posts: 209
Justinmichael is on a distinguished road
Default

Yeah,

Code:
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
Don't forget to drain / release it at the end of the loop though.
__________________
Justinmichael is offline   Reply With Quote
Old 09-20-2010, 09:06 AM   #6 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 109
freedoom is on a distinguished road
Default

Thanks Just!
In general, how do I know if an item goes autorelease or not?
freedoom is offline   Reply With Quote
Old 09-20-2010, 01:46 PM   #7 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 13
hcarsten is on a distinguished road
Default

Quote:
Originally Posted by freedoom View Post
Thanks Just!
In general, how do I know if an item goes autorelease or not?
In General you have to know this by the documentation. I think there is no way to find out if an object had been added to a pool. NSAutoreleasePool just has a method to addObjects. Anyway the implementation is pretty much just an Array. So the "drain" of the pool will just only send a "release" to any object added.

But you can safely add retain/release to manage the object for yourself.
hcarsten 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: 318
14 members and 304 guests
2ndSegment, cayladv57, cgokey, dermotos, djohnson, Domele, Hamad, linkmx, markuschow, pungs, Sloshmonster, teebee74, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

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