开发者

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:@"&lt;" withString:@"<"];
json_var = [json_var stringByReplacingOccurrencesOfString:@"&gt;" 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=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>" withString:@""];

json_var = [json_var stringByReplacingOccurrencesOfString:@"<?xml version=&quot;1.0&quot; encoding=&quot;windows-1252&quot;?>" 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:

  1. remove line [json_var release]
  2. replace

    json_var = [[NSString alloc] initWithData:myMutableData encoding:NSUTF8StringEncoding ];
    

    with

    json_var = [[[NSString alloc] initWithData:myMutableData encoding:NSUTF8StringEncoding ]autorelease];
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜