| Paste number 21630: | NSURLConnection leak |
| Pasted by: | avium |
| When: | 3 years, 7 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+GOU |
| Channel: | None |
| Paste contents: |
#import <Cocoa/Cocoa.h>
@interface NSURLConnectionTest : NSObject {}
@end
@implementation NSURLConnectionTest
+ (NSString*)gStringWithContentsOfURL: (NSURL*)url encoding: (NSStringEncoding)anEncoding error: (NSError**)anError {
NSData *contents = nil;
NSURLResponse *urlResponse = nil;
// create the request
NSURLRequest *theRequest = [NSURLRequest requestWithURL: url cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 5.0];
contents = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: &urlResponse error: anError];
//DebugLog(@"%s: URL Response: '%@'", __FUNCTION__, urlResponse);
if (!urlResponse) return nil;
return [[[NSString alloc] initWithData: contents encoding: anEncoding] autorelease];
}
- (void)_testURLConnection: (id)sender {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *result = nil;
NSURL *testURL = [NSURL URLWithString: @"http://www.asdf.com/"];
result = [NSURLConnectionTest gStringWithContentsOfURL: testURL encoding: NSUTF8StringEncoding error: nil];
printf("URL request complete...\n");
[pool release];
}
- (void)testURLConnection {
int i;
for (i = 0; i < 100000; i++) {
printf("Detaching new thread...\n");
[NSThread detachNewThreadSelector: @selector(_testURLConnection:) toTarget: self withObject: nil];
sleep(1);
}
}
@end
int main(int argc, const char *argv[]) {
NSURLConnectionTest *t = [[NSURLConnectionTest alloc] init];
[t testURLConnection];
return 1;
}
This paste has no annotations.