Determine selected photos in AGImagePickerController - iphone

I'm using AGImagePickerController. Im having a hard time figuring out how to import the images selected into my iCarousel which is in another carousel. I know that the success block in it contains the selected image. I can't seem to import it in my awakeFromNib or putting it in an array.
here is my code that calls the AGImagePickerController:
-(IBAction) cameraRoll {AGImagePickerController *imagePickerController = [[AGImagePickerController alloc] initWithFailureBlock:^(NSError *error) {
if (error == nil)
{
NSLog(#"User has cancelled.");
[self dismissModalViewControllerAnimated:YES];
} else
{
NSLog(#"Error: %#", error);
// Wait for the view controller to show first and hide it after that
double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self dismissModalViewControllerAnimated:YES];
});
}
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
} andSuccessBlock:^(NSArray *info) {
NSLog(#"Info: %#", info);
[self dismissModalViewControllerAnimated:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
}];
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}
In my awakeFromNib:
- (void)awakeFromNib
{
if (self) {
self.images = [NSMutableArray arrayWithObjects:#"111.jpg",
#"112.jpg",
#"113.jpg",
#"114.jpg",
#"115.jpg",
#"116.jpg",
#"117.jpg",
#"118.png",
#"119.jpg",
#"120.jpg",
nil];
}
}
Then I implement this for my carousel :
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
//create a numbered view
UIView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[images objectAtIndex:index]]];
return view;
}

You should be able to look at the contents of the info array using your NSLog statement. It would have been helpful to see the contents of that log statement.
I found this here and it might work:
for (i = 0; i < info.count; i++) {
ALAssetRepresentation *rep = [[info objectAtIndex: i] defaultRepresentation];
UIImage * image = [UIImage imageWithCGImage:[rep fullResolutionImage]];
}
Edit:
You need to save the images (either in memory or by writing them to files) after the user selects them. If you want to write them to files, you can do that like so:
[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
If the AGImagePickerController code is in your iCarousel class, you can just add the images to your images array. Your successBlock would look something like this:
self.images = [NSMutableArray new];
for (i = 0; i < info.count; i++) {
ALAssetRepresentation *rep = [[info objectAtIndex: i] defaultRepresentation];
UIImage * image = [UIImage imageWithCGImage:[rep fullResolutionImage]];
[self.images addObject:image];
}
And finally, in your iCarousel code you need to read the images either from your images array or from the disk (depending on where you chose to save them). If you are saving them in memory
your code could look like this:
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
return [[UIImageView alloc] initWithImage:[self.images objectAtIndex:index]];
}
Or, if you decided to save the images to disk then you could recreate the UIImage objects using [UIImage imageWithContentsOfFile:filePath];.

Related

ALAsset Photo Library Image Performance Improvements When Its Loading Slow

Hi i've got a problem with display an image on my scrollView.
At first i create new UIImageView with asset url:
-(void) findLargeImage:(NSNumber*) arrayIndex
{
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep;
if([myasset defaultRepresentation] == nil) {
return;
} else {
rep = [myasset defaultRepresentation];
}
CGImageRef iref = [rep fullResolutionImage];
itemToAdd = [[UIImageView alloc] initWithFrame:CGRectMake([arrayIndex intValue]*320, 0, 320, 320)];
itemToAdd.image = [UIImage imageWithCGImage:iref];
[self.scrollView addSubview:itemToAdd];
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(#"Cant get image - %#",[myerror localizedDescription]);
};
NSURL *asseturl = [NSURL URLWithString:[self.photoPath objectAtIndex:[arrayIndex intValue] ]];
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:asseturl
resultBlock:resultblock
failureBlock:failureblock];
}
Where itemToAdd is a UIImageView define in interface:
__block UIImageView *itemToAdd;
And scrollView define as a property:
#property (nonatomic, strong) __block UIScrollView *scrollView;
Then in my viewWillAppear i do this:
- (void) viewWillAppear:(BOOL)animated {
self.scrollView.delegate = self;
[self findLargeImage:self.actualPhotoIndex];
[self.view addSubview:self.scrollView];
}
But image doesnt appear, should i refresh self.view after add image to scrollView, or should do something else?
ALAssetsLibrary block will execute in separate thread. So I suggest to do the UI related stuffs in main thread.
To do this either use dispatch_sync(dispatch_get_main_queue() or performSelectorOnMainThread
Some Important Notes:
Use AlAsset aspectRatioThumbnail instead of fullResolutionImage for high performance
Example:
CGImageRef iref = [myasset aspectRatioThumbnail];
itemToAdd.image = [UIImage imageWithCGImage:iref];
Example:
-(void) findLargeImage:(NSNumber*) arrayIndex
{
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
CGImageRef iref = [myasset aspectRatioThumbnail];
dispatch_sync(dispatch_get_main_queue(), ^{
itemToAdd = [[UIImageView alloc] initWithFrame:CGRectMake([arrayIndex intValue]*320, 0, 320, 320)];
itemToAdd.image = [UIImage imageWithCGImage:iref];
[self.scrollView addSubview:itemToAdd];
});//end block
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(#"Cant get image - %#",[myerror localizedDescription]);
};
NSURL *asseturl = [NSURL URLWithString:[self.photoPath objectAtIndex:[arrayIndex intValue] ]];
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:asseturl
resultBlock:resultblock
failureBlock:failureblock];
}
Also change the order of viewWillAppear()
- (void) viewWillAppear:(BOOL)animated {
self.scrollView.delegate = self;
[self.view addSubview:self.scrollView];
[self findLargeImage:self.actualPhotoIndex];
}
You are manipulating the view from another thread.
You must use the main thread for manipulating the view.
Add image to scrollView using:
dispatch_async(dispatch_get_main_queue(), ^{
[self.scrollView addSubview:itemToAdd];
}
or using:
[self.scrollView performSelectorOnMainThread:#selector(addSubview:) withObject:itemToAdd waitUntilDone:NO];
Please refer:
NSObject Class Reference
GCD

UIImagePickerController After taking 5 images sequentially Terminates Application

//This method Launches the picker to take the picture from camera.
-(IBAction)takeyouphoto:(id)sender
{
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
// Create image picker controller
UIImagePickerController *imagePicker2 = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker2.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
imagePicker2.delegate = self;
// Allow editing of image ?
imagePicker2.allowsEditing= NO;
// Show image picker
[self presentModalViewController:imagePicker2 animated:YES];
}
}
//This is ImagePicker Delegate method.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
#try {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *resultimage=nil;
//I am using iOS5, so we can not use NSAutoreleasePool
resultimage=[info objectForKey:UIImagePickerControllerOriginalImage] ;
//This Launches the HUD (Activity Indicator) because ImagePicker ususally takes 5
//seconds to launch image.
[self showHUD:resultimage];
}
}
[picker dismissModalViewControllerAnimated:YES];
}
-(void)showHUD:(UIImage *)resultimage
{
[[Singleton sharedmysingleton] stoptimer];
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = #"Loading Image";
//HUD.detailsLabelText=#"Loading";
//Below call on showWhileExecuting of the MBProgressHuD class has its own NSAutoreleasePool
//Defined in MGProgressHUD class. it also runs the method showimageincell; in separate
//thread.
[HUD showWhileExecuting:#selector(showimagesincell:) onTarget:self withObject:resultimage animated:YES];
}
-(void)showimagesincell:(UIImage *)image
{
appDelegate.tabbarcontroller.tabBar.userInteractionEnabled=NO;
NSError *error;
UIImage *resultImage=[self scale:image toSize:image.size];
//UIImage *resultImage = [[UIImage alloc] initWithCGImage:imgRefCrop scale:1.0 orientation:resultimage.imageOrientation];
//resultimage.imageOrientation
NSData *imagedata=UIImageJPEGRepresentation(resultImage, 0.7);//(resultImage);
UIImage *smallimage=[self scale:image toSize:CGSizeMake(100, 100)];
NSData *smallimagedata=UIImageJPEGRepresentation(smallimage, 0.7);
/* NSString *imagetypeid=[Fetchsavefromcoredata getImagenameandImageidfromdatabase:#"Mobile_ImageType" attributename:#"imageType" predicate:imagetypetxtfield.text];
//write image to document directory
NSString *localImagedir=[photodirpath stringByAppendingPathComponent:selectedvinnumber];
NSString *datetime=[Singleton imagedateandtime];
NSString *imagename=[NSString stringWithFormat:#"%#_%#.png",imagetypeid,datetime];
NSString *localImagePath=[localImagedir stringByAppendingPathComponent:imagename];
[imagedata writeToFile:localImagePath atomically:YES];*/
[self performSelectorOnMainThread:#selector(updatetableview) withObject:nil waitUntilDone:NO];
}
-(void)updatetableview
{
[[Singleton sharedmysingleton] starttimer];
[self viewWillAppear:YES];
}
-(UIImage *)scale:(UIImage *)image toSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
//Above is all my code, I have tried to find it on diffrent forums but I have not fixed it yet.
//Any help will be appreciated. Thanks in advance
The white screen issue is fixed by keeping the image returned by the UIIMagePickerController delegate method into an #autoreleasepool (for iOS5). It solved the problem, we can not use NSAutoreleasePool in ARC code.
Here the line of code in didFinishPickingMediaWithInfo: delegate method
UIImage *resultimage=nil;
#autoreleasepool
{
//I am using iOS5, so we can not use NSAutoreleasePool
resultimage=[info objectForKey:UIImagePickerControllerOriginalImage] ;
}
Below the UIImagePickerController delegate method after implementing #autoreleasepool
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
#try {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *resultimage=nil;
#autoreleasepool
{
//I am using iOS5, so we can not use NSAutoreleasePool
resultimage=[info objectForKey:UIImagePickerControllerOriginalImage] ;
}
//This Launches the HUD (Activity Indicator) because ImagePicker ususally takes 5
//seconds to launch image.
[self showHUD:resultimage];
}
}
[picker dismissModalViewControllerAnimated:YES];
}

Memory management issue with AssetsLibrary framework

My code take a lot time to load images from gallery. I store url of each image in database and then load them from gallery using AssetsLibrary framework. But i notice that it take more memory and so that i receive memory warning. after some time app is crash down. Here i put my code.
-(void) nextImageLoad
{
// ALAssetsLibrary* self. assetslibrary=[[ALAssetsLibrary alloc] init];
self.myScrollView.pagingEnabled=YES;
NSLog(#"current :- %d, loaded_photo :- %d, [imageData count] :- %d",current, loaded_photo, [imageData count]);
if(current>loaded_photo && current < [imageData count])
{
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
self.rep = [myasset defaultRepresentation];
CGImageRef iref = [self.rep fullResolutionImage];
if (iref)
{
UIImageView *temp = [[UIImageView alloc] initWithFrame:CGRectMake(self.x, y, 300, 300)];
temp.image=[UIImage imageWithCGImage:iref];
[self.myScrollView addSubview:temp];
[temp release];
[myScrollView setContentSize:CGSizeMake(self.x+600, 410)];
[myScrollView setAutoresizesSubviews:YES];
}
else
{
}
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(#"booya, cant get image - %#",[myerror localizedDescription]);
};
[self.assetslibrary assetForURL:[NSURL URLWithString:[[self.imageData objectAtIndex:current] valueForKey:#"photo_url"] ]
resultBlock:resultblock
failureBlock:failureblock];
self.x=self.x+320;
loaded_photo= loaded_photo+1;
}
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
lastContentOffset = scrollView.contentOffset.x;
}
-(void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
if (lastContentOffset > scrollView.contentOffset.x)
{
NSLog(#"left");
if(current>0)
current=current-1;
}
else if (lastContentOffset < scrollView.contentOffset.x)
{
NSLog(#"right");
current=current+1;
[self nextImageLoad];
}
lastContentOffset = scrollView.contentOffset.x;
}
Hard to know if this is the problem, but try creating an autorelease pool inside all your blocks:
block = ^(ALAsset *myasset)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// rest of block here
[pool release];
}
Also remember if you return early inside the block, you need to release the pool object before your return statement.

Saving a thumbnail on a background thread

I'm trying to create thumbnails (288x288) of selected photos from iPad photo library. I have an array of ALAsset objects presented in a UITableView and as I select a row, a larger preview (288x288) of that image is displayed. In order to prevent main thread blocking, I'm trying to create the thumbnail on a background thread and also cache a copy of the thumbnail to the file system.
In a view controller when a tableview row is selected, I call loadPreviewImage in background:
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// get the upload object from an array that contains a ALAsset object
upload = [uploads objectAtIndex:[indexPath row]];
[self performSelectorInBackground:#selector(loadPreviewImage:)
withObject:upload];
}
I pass a custom upload object that contains asseturl property:
- (void)loadPreviewImage:(MyUploadClass*)upload
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
UIImage *preview = [upload previewImage];
[self performSelectorOnMainThread:#selector(setPreviewImage:)
withObject:preview
waitUntilDone:YES];
[pool release];
}
This is called on main thread to display the thumbnail after it's loaded:
- (void)setPreviewImage:(UIImage*)image
{
self.imageViewPreview.image = image;
[self layoutSubviews];
}
This is a method of MyUploadClass:
- (UIImage *)previewImage
{
__block UIImage *previewImage = [[UIImage imageWithContentsOfFile:
[self uploadPreviewFilePath]] retain];
if (previewImage == nil && asseturl)
{
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library assetForURL:self.asseturl resultBlock:^(ALAsset *asset)
{
ALAssetRepresentation *rep = [asset defaultRepresentation];
previewImage = [UIImage imageWithCGImage: [rep fullScreenImage]];
previewImage = [[previewImage resizedImageWithContentMode:UIViewContentModeScaleAspectFit
bounds:CGSizeMake(288, 288)
interpolationQuality:kCGInterpolationHigh] retain];
NSData *previewData = UIImageJPEGRepresentation(previewImage, 1.0);
[previewData writeToFile:[self uploadPreviewFilePath] atomically:YES];
}
failureBlock:^(NSError *error){ }];
[library release];
}
return [previewImage autorelease];
}
The problem is that I always get nil previewImage the first time and only after the thumbnail is cached I get an image object. What am I doing wrong? Is there a better approach to this problem?
I didn't clearly understand how the resultBlock of ALAssetsLibrary operates, my mistake was to think that the execution is linear. It turns out that in my case the resultBlock executes on the main thread while the rest of the code in previewImage executes on a background thread. I was getting nil because previewImage returned before resultBlock had a chance to end its execution. I solved the problem by replacing previewImage with the following method:
- (void) loadPreviewImage:(CGSize)size withTarget:(id)target andCallback:(SEL)callback
{
NSString *path = [self uploadPreviewFilePath];
UIImage *previewImage = [UIImage imageWithContentsOfFile:path];
if (previewImage == nil && asseturl)
{
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library assetForURL:self.asseturl resultBlock:^(ALAsset *asset)
{
if (asset) {
ALAssetRepresentation *rep = [asset defaultRepresentation];
UIImage *img = [UIImage imageWithCGImage: [rep fullScreenImage]];
img = [img resizedImageWithContentMode:UIViewContentModeScaleAspectFit
bounds:size interpolationQuality:kCGInterpolationHigh];
NSData *previewData = UIImageJPEGRepresentation(img, 1.0);
[previewData writeToFile:path atomically:YES];
[target performSelectorOnMainThread:callback
withObject:img
waitUntilDone:YES];
}
}
failureBlock:^(NSError *error){ }];
[library release];
}
else {
[target performSelectorOnMainThread:callback withObject:img waitUntilDone:YES];
}
}

Memory allocation, release and NSURLConnection in iPhone app

I'm hoping someone can help me with this. I'm struggling to find an answer to what should be an easy question. By the way, this is my first major obj-c project after years of using c and c# so feel free to point out things I'm failing on.
I have an iPhone app designed to load an album of photos into a UIScrollView. It also has a random image function which uses the same process but only displays a single image. It works like so:
Read an external XML feed (stored on ruby-on-rails website) which contains a path to a random url of photo once parsed.
Content of URL is downloaded using NSURLConnection to NSData.
ScrollView is created and pushed
Subclassed UIView allocs an UIImageView, allocs a UIImage with the NSData which, inits the UIImageView with the UIimage and finally adds the imageview to the UIView.
The parent view then adds the UIView to the UIScrollView which is then pushed to the front.
This process occurs again when when the next random image is required. It also uses the same process when displaying an entire album of images except several UIViews are added to the UIScrollView.
The problem is, despite using release and delloc where appropriate, the activity tool indicates that the memory used by NSURLConnection and UIImage isn't being released from memory when the next image is requested. This is further proven by building the app to the iPhone. Requesting several images in a row causes the app the crash presumably from memory consumption.
Below is some of the code as I'm unable to post the entire project due to contractual agreements.
URLDownload class (uses DataDownload)
#implementation URLDownload
-(NSData *)GetURL:(NSURL *)strURL
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
DataDownload *request = [DataDownload alloc];
request.strURL = strURL;
[request init];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
while (request.isLoading && [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
[pool release];
return [request urlData];
[request release];
}
DataDownload class
#implementation DataDownload
#synthesize urlData, connection, strURL, isLoading;
- (id)init
{
if(self = [super init])
{
self.isLoading = YES;
NSURLRequest *dataRequest = [NSURLRequest requestWithURL:self.strURL
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:60];
/* establish the connection */
self.connection = [[NSURLConnection alloc]
initWithRequest:dataRequest
delegate:self
];
if (connection == nil) {
self.urlData = nil;
} else {
self.urlData = [NSMutableData data];
}
}
return self;
}
- (void)dealloc {
[connection cancel];
[connection release];
[urlData release];
[strURL release];
[super dealloc];
}
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse {
return nil;
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse*)response
{
[urlData setLength:0];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)incrementalData
{
[self.urlData appendData:incrementalData];
}
-(void)connectionDidFinishLoading:(NSURLConnection*)connection
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
self.isLoading = NO;
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
self.isLoading = NO;
}
#end
ImageView subclass
#implementation ImageView
#synthesize strURL, imvImageView, image, currentlyRotated, imgOptionsView, startDate;
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.imvImageView = [UIImageView alloc];
if (self.strURL != nil){
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
NSData *datImageData = [NSData dataWithContentsOfURL: [NSURL URLWithString:self.strURL]];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
self.image = [UIImage imageWithData: datImageData];
CGSize imgSize = image.size;
CGFloat fltWidth = imgSize.width;
CGFloat fltHeight = imgSize.height;
[imvImageView initWithImage:image];
// If landscape rotate image
if (fltWidth > fltHeight){
imvImageView.frame = CGRectMake(-80.0, 80.0, 480.0, 320.0);
CGAffineTransform rotate = CGAffineTransformMakeRotation(-1.57079633);
[imvImageView setTransform:rotate];
self.currentlyRotated = YES;
}else{
imvImageView.frame = CGRectMake(0.0, 0.0, 320.0, 480.0);
self.currentlyRotated = NO;
}
[image release];
}else{
self.image = [UIImage alloc];
[imvImageView initWithImage:image];
[image release];
}
[self addSubview:imvImageView];
}
[imvImageView release];
return self;
}
- (void)drawRect:(CGRect)rect {
// Drawing code
}
- (void)dealloc {
[strURL release];
[imvImageView release];
[image release];
[imgOptionsView release];
[startDate release];
[super dealloc];
}
Sample code of how images are being displayed
- (void)displayImage:(NSString *)strURL {
NSString *strFullURL = #"http://www.marklatham.co.uk";
strFullURL = [strFullURL stringByAppendingString:strURL];
self.scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
[scroller setContentSize:CGSizeMake(320.0, 540.0)];
[self.view addSubview:scroller];
CGRect rect = CGRectMake(0.0, 0.0, 320.0, 480.0);
self.imageView = [ImageView alloc];
imageView.strURL = strFullURL;
[imageView initWithFrame:rect];
[scroller addSubview:imageView];
[scroller release];
[imageView release];
}
The following images show all allocations to illustrate what's happening. 1 shows alloc on startup, 2 shows after first image is loaded and 3 after after second image.
http://www.gretanova.com/misc/iphone/1.png & 2.png & 3.png
Thanks everyone,
Lee
A couple of things stick out. For example within the URLDownload class the call to [request release] will never be reached as its placed after the return statement
return [request urlData];
[request release];