- (BOOL) webView: (UIWebView *) webView shouldStartLoadWithRequest: (NSURLRequest *) request navigationType: (UIWebViewNavigationType) navigationType
{
NSString * urlString = [[request URL] absoluteString];
if ([urlString hasPrefix: @ "cmd:"]) {
NSRange range = [urlString rangeOfString: "?" @] ;/ / This does not require the release of non-pointer type it?
NSString * cmd = [[urlString substringToIndex: range.location] substringFromIndex: 4] ;/ / Why this variable in the final release will hang?
NSString * paramsString = [urlString substringFromIndex: range.location + range.length];
NSArray * params = [paramsString componentsSeparatedByString: @ "&"];
if ([cmd caseInsensitiveCompare: @ "changeLocation"] == NSOrderedSame) {
NSString * lat, * lng;
for (NSObject * item in params) {
NSString * param = (NSString *) item;
range = [param rangeOfString: @ "="];
NSString * name = [param substringToIndex: range.location];
NSString * value = [param substringFromIndex: range.location + 1];
if ([name caseInsensitiveCompare: @ "lat"] == NSOrderedSame) {
lat = value;
/ / [Lat retain];
} Else if ([name caseInsensitiveCompare: @ "lng"] == NSOrderedSame) {
lng = value;
/ / [Lng retain];
}
/ / [Name release];
/ / [Value release];
/ / [Param release];
}
[Coordinate setText: [NSString stringWithFormat: @ "current latitude is:% @ Longitude is:% @", lat, lng]];
/ / [Lat release];
/ / [Lng release];
}
/ / [Cmd release];
/ / [ParamsString release];
/ / [Params release];
}
return YES;
}
Reply:
Hey, in principle, you alloc or retain, and you release, you do not alloc or retain, and do not release.
Reply:
You mean this:
NSString * cmd = [[urlString substringToIndex: range.location] substringFromIndex: 4];
Do not need to release too? ? But when I debug cmd observation of retainCount 1 ah. . .
Reply:
The different methods of creating objects from talking about:
1. Use alloc / init to create objects
NSArray * array = [[NSArray alloc] init];
/ / Need to manually release
[Array release];
2.autorelease
NSArray * array = [[[NSArray alloc] init] autorelease];
/ / No need to manually release, but to the auto-release pool
3 class method
NSArray * array = [NSArray array];
/ / No need to manually release, has been set to automatically release
Reply:
Thank you, that I do not need to retain and release here, is not it? ?
Reply:
Do not. . .
Generally, NSString alloc temporary variables and they do not retain, declared out of the need to manually release the
The system will default to automatically add them inside, belong to the system management, rather than developers
Another point to note is that almost all of the object pointer (not a pointer is not discovered, it may be my lack of experience), pay attention to the release point of the memory space, generally there is no problem. Just know that at the memory of their own claims management, or their own management systems on the OK
Reply:
NSRange range = [urlString rangeOfString: @ "?"];
This is also a pointer to it? ? Pointer not to add an asterisk Why? ?
Reply:
object alloc, init, new needs created release, retain objects need to manually release, is not required to release the basic data types, remember almost, I can see the specific blog. It depends on the version you use Xcode, iphone mac development and general development is different. But above that principle will not change.
Reply:
LZ brother suggested a look book! Another signature is very domineering brother LZ!
No comments:
Post a Comment