Questions tagged [nsautoreleasepool]

an OS X API class, used to support Cocoa’s reference-counted memory management system

270 questions
96
votes
7 answers

How does the NSAutoreleasePool autorelease pool work?

As I understand it, anything created with an alloc, new, or copy needs to be manually released. For example: int main(void) { NSString *string; string = [[NSString alloc] init]; /* use the string */ [string release]; } My question,…
76
votes
4 answers

What is the equivalent of @autoreleasepool in Swift?

In Swift, I notice there is no @autoreleasepool{} construct, although Swift does use ARC. What is the proper way to manage an autoreleasepool in Swift, or has it been removed for some reason?
Skotch
  • 3,072
  • 2
  • 23
  • 43
73
votes
1 answer

What is autoreleasepool?

Possible Duplicate: Why use Autorelease pool? All Objective-C starting page opens with a default @autoreleasepool{...} statement under the main function declaration. But what is this statement actually doing? The new Objective-C releases…
moray95
  • 937
  • 2
  • 9
  • 12
31
votes
5 answers

NSAutoreleasePool is unavailable

I am following "Programming in Objective-C" 3rd edition and I am having problems with the first example. I keep getting this error: Semantic Issue: 'NSAutoreleasePool' is unavailable: not available in automatic reference counting mode Here is…
Greg
  • 311
  • 1
  • 3
  • 4
30
votes
1 answer

Why use Autorelease pool?

I know there is an autorelease pool created in the main method and all the objects that receive autorelease message get stored in this pool and get released when the pool drains out. But it is always said to avoid autoreleasing objects to avoid…
Aisha
  • 1,559
  • 5
  • 20
  • 37
25
votes
1 answer

Is @autoreleasepool still required for modern iOS 8 NSOperation usage?

I’ve read through Concurrency Programming Guide In the guide the text states that GCD dispatch queues define their own @autoreleasepool pools and mentions that it’s still recommended to define one at a per dispatch level, yet for NSOperation…
Maxim Veksler
  • 29,272
  • 38
  • 131
  • 151
19
votes
3 answers

Under ARC, is it still advisable to create an @autoreleasepool for loops?

Let's say that I have a loop that returns a bunch of autoreleased NSData objects... NSData* bigData = ... while(some condition) { NSData* smallData = [bigData subdataWithRange:...]; //process smallData } Under ARC, should I still wrap an…
19
votes
2 answers

Using ARC, is it fatal not to have an autorelease pool for every thread?

I read this: If you ever create a secondary thread in your application, you need to provide it with its own autorelease pool. Autorelease pools and the objects they contain are discussed further in in the iOS 5 Developer cookbook. I'm compiling…
user4951
  • 32,206
  • 53
  • 172
  • 282
17
votes
1 answer

Does an @autoreleasepool {} drain when returning / exiting early?

Consider this example: - (void)doSomething { @autoreleasepool { if (someCondition) { /* ... allocate some autoreleased objects here ... */ return; } } } Previously, with manual NSAutoreleasePools, if we…
Martijn Thé
  • 4,674
  • 3
  • 29
  • 42
17
votes
3 answers

iOS autorelease pool blocks

I was reading the documentation from apple about memory management when I got to autorelease pool blocks and something got me thinking. Any object sent an autorelease message inside the autorelease pool block is released at the end of the…
Teo
  • 3,394
  • 11
  • 43
  • 73
15
votes
1 answer

Why does Xcode 4.2 use @autoreleasepool in main.m instead of NSAutoreleasePool?

I've noticed that there is a different way in Xcode 4.2 to start the main function: int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, …
Foo
  • 596
  • 2
  • 5
  • 21
13
votes
2 answers

What is the difference between NSAutoreleasePool and @autoreleasepool block?

I want to know what are the differences between NSAutoreleasePool and @autoreleasepool block.I have gone through a number of questions but didn't get any satisfying answer.Till now I came to know that in ARC we can't use NSAutoreleasePool and…
Imran
  • 1,715
  • 2
  • 20
  • 42
11
votes
5 answers

When does autorelease actually cause a release in Cocoa Touch?

I understand you need to be careful with autorelease on iOS. I have a method that is returning an object it allocs which is needed by the caller, so in this situation -- as I understand it -- I need to send autorelease to the object in the callee…
Ian1971
  • 3,666
  • 7
  • 33
  • 61
10
votes
3 answers

Autorelease pools and when release is called under iOS

I wanted to get something clarified. Lets say I have the following code: - (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; for (int i = 0; i < 5000000; i++) { NSString *s = [NSString stringWithFormat:@"Hello, %@!",…
James Richard
  • 1,525
  • 12
  • 18
9
votes
2 answers

does NSThread create autoreleasepool automatically now?

I have test code like this - (void)viewDidLoad { [super viewDidLoad]; NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(test) object:nil]; [thread start]; } -(void)test { MyClass *my = [[[MyClass alloc]…
eliudnis
  • 239
  • 3
  • 6
1
2 3
17 18