BigT
BigT

Reputation: 1433

ARC Autoreleased with no pool in place

I am using ARC in my code and I am getting the error

Object 0x781b8e0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug

The line it breaks on is

  return UIApplicationMain(argc, argv, nil, NSStringFromClass([HomePageAppDelegate class]));

Since I am using ARC I cannot put an NSAutoReleasePool around it like I usually would. What can I use in order to fix this error?

Upvotes: 0

Views: 997

Answers (3)

Sumanth
Sumanth

Reputation: 4921

use this on the line where it showing the warning

@autoreleasepool{
}

Upvotes: 0

Phillip Mills
Phillip Mills

Reputation: 31016

Create a new test app with ARC enabled. Look at the code in "main.m" to see what Apple recommends.

Upvotes: 0

Richard J. Ross III
Richard J. Ross III

Reputation: 55563

You use the @autoreleasepool construct:

@autoreleasepool {
    // main code here
}

This creates a NSAutoReleasePool with the same scope as the brackets, and it can also be used in MRC code as well. It has the advantages of being cleaned up when exceptions occur, and can easily be used to dispatch threads safely.

To read more, visit this article on Transitioning to ARC Release Notes

Upvotes: 6

Related Questions