- As long as there is a variable pointing to an object, that object stay in memory. When the pointer gets a new value or ceases to exist, the associated object is released.This is true for all variables:instance variables,synthesized properties, adn even local variables.
- “weak” pointer. Variables that are weak can still point to objects but they do not become owners.
- Please change the
Complier for C/C++/Object-c
option toApple LLVM compiler 3.0
. - Please set
Other Waring Flags
option to-Wall
. - Please set
Run Static Analyzer
option toYes
. - Please set
Objective-c Automatic Reference Counting
option toYes
. - Some files needn’t to convert to ARC support, use the
-fno-objc-arc
flag. You will get this error when your code does the following:
switch (X) { case Y: NSString *s = ...; break; }
you need do this:
switch (X) { case Y: { NSString *s = ...; break; } }
If instace variables are a part of the internals of your class and not something you want expose in its public interface. you can move the instace variables from interface section to implementation section. some codes from .h file as following:
#import <UIKit/UIKit.h>
@interface MainViewController : UIViewController
<UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate,
NSXMLParserDelegate>
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (nonatomic, retain) IBOutlet UISearchBar *searchBar;
@end
move the instace variables to implementation section as following:
@implementation MainViewController
{
NSOperationQueue *queue;
NSMutableString *currentStringValue;
}
- Generally, dealloc method isn’t need.The only reason for keeping a dealloc method around is when you need to free certain resources that do not fall under ARC’s umbrella. Examples of this are calling CFRelease() on Core Foundation objects, calling free() on memory that you allocated with malloc(), unregistering for notifications, invalidating a timer, and so on.
Toll-Free Bridging
Change ownership from Core Foundation to Objecttive-C, use CFBridgingRelease().
Change ownership from Objective-C to Core Foundation, use CFBridgingRetain().
Want to use one type temporarily as if it were another without owership change, use __bridge.