release memory in my ipad
hi all freind im noob in ipad ,please who tell me why i can't release json_var?
NSData* myMutableData = [NSURLConnection sendSynchronousRequest:request returningResponse:&WSresponse error:&WSerror];
NSLog(@"slt%d",[myMutableData length]);
json_string=nil;
json_var = [[NSString alloc] initWithData:myMutableData encoding:NSUTF8StringEncoding ];
json_var = [json_var stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
json_var = [json_var stringByReplacingOccurrencesOfString:@">" withString:@">"];
json_var = [json_var stringByReplacingOccurrencesOfString:@"<?xml....... string\">" withString:@""];
json_var = [json_var stringByReplacingOccurrencesOfString:@"</return></ns1:getDatasResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>" withString:@""];
json_var = [json_var stringByReplacingOccurrencesOfString:@"<?xml version="1.0" encoding="UTF-8"?>" withString:@""];
json_var = [json_var stringByReplacingOccurrencesOfString:@"<?xml version="1.0" encoding="windows-1252"?>" withString:@"<?xml version=\"1.0\" encoding=\"windows-1252\"?>"];
开发者_如何学C NSString *data13=[[NSString alloc] initWithString:json_var];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
IDComp = [IDComp stringByReplacingOccurrencesOfString:@"/" withString:@":"];
NSString *test1 = [IDComp stringByAppendingString:@".xml"];
NSString *test2 = [documentsDirectory stringByAppendingString:@"/"];
NSString *test3 = [test2 stringByAppendingString:test1];
NSString *file2 = [NSString stringWithFormat:test3];
[data13 writeToFile:file2 atomically:YES];
[data13 release];
[json_var release];
You don't need to release string json_var
because you assign to it autoreleased object (method stringByReplacingOccurrencesOfString:
returns autoreleased NSString
).
If you don't want memory leaks that you should do next:
- remove line
[json_var release]
replace
json_var = [[NSString alloc] initWithData:myMutableData encoding:NSUTF8StringEncoding ];
with
json_var = [[[NSString alloc] initWithData:myMutableData encoding:NSUTF8StringEncoding ]autorelease];
精彩评论