Created
October 16, 2012 10:21
-
-
Save piaoapiao/3898513 to your computer and use it in GitHub Desktop.
Asihttp leak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.m | |
// testAsihttpModel | |
// | |
// Created by wgdadmin on 12-9-8. | |
// Copyright (c) 2012年 wgdadmin. All rights reserved. | |
// | |
#import "ViewController.h" | |
#import "ASIHTTPRequest.h" | |
@interface ViewController () | |
@end | |
@implementation ViewController | |
-(void)jumpTip:(NSString *)string | |
{ | |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"test" message:string delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:nil, nil]; | |
[alert show]; | |
[alert release]; | |
} | |
-(void)threadGetDate | |
{ | |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
NSString *city = @"beijing"; | |
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/geocode/json?address=%@&sensor=true", city]]; | |
NSLog(@"city:%@",city); | |
// NSURL *url2 = [[[NSURL alloc] initWithString:@"asdf"] autorelease]; | |
ASIHTTPRequest *request =[[[ASIHTTPRequest alloc] initWithURL:url]autorelease]; | |
request.delegate = self; | |
//[request startAsynchronous]; | |
[request startSynchronous]; | |
NSString *string = [request responseString]; | |
// NSLog(@"string:%@",string); | |
[string retain]; | |
[pool drain]; | |
[url release]; | |
// [url2 release]; | |
if(nil != string ) | |
{ | |
[self performSelectorOnMainThread:@selector(jumpTip:) withObject:string waitUntilDone:YES]; | |
} | |
[string release]; | |
} | |
-(void)getDate:(id)sender | |
{ | |
/* | |
TODO:perforce on new thread | |
*/ | |
// NSString *city = [NSString stringWithFormat:@"%@",nameField.text]; | |
[NSThread detachNewThreadSelector:@selector(threadGetDate) toTarget:self withObject:nil]; | |
/* | |
TODO:perforce on main thread | |
*/ | |
// NSString *city = @"beijing"; | |
// NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/geocode/json?address=%@&sensor=true", city]]; | |
// NSLog(@"city:%@",city); | |
// ASIHTTPRequest *request =[[[ASIHTTPRequest alloc] initWithURL:url]autorelease]; | |
// request.delegate = self; | |
// [request startSynchronous]; | |
// NSString *string = [request responseString]; | |
// if(nil != string) | |
// { | |
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"test" message:string delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:nil, nil]; | |
// [alert show]; | |
// [alert release]; | |
// } | |
} | |
- (void)viewDidLoad | |
{ | |
UIButton *mapBtn = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 100, 30)]; | |
[mapBtn setTitle:@"get" forState:UIControlStateNormal]; | |
[mapBtn addTarget:self action:@selector(getDate:) forControlEvents:UIControlEventTouchUpInside]; | |
[self.view addSubview:mapBtn]; | |
[mapBtn release]; | |
nameField = [[UITextField alloc] initWithFrame:CGRectMake(50, 150, 80, 30)]; | |
[self.view addSubview:nameField]; | |
nameField.backgroundColor = [UIColor redColor]; | |
nameField.delegate = self; | |
[nameField release]; | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
- (void)viewDidUnload | |
{ | |
[super viewDidUnload]; | |
// Release any retained subviews of the main view. | |
} | |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation | |
{ | |
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment