How big are the images? And how many are you trying to send?
I can't seem to find an easy way to implement an NSInputStream
using AFNetworking
, but there's definitely one thing you should try, which is avoiding putting big objects in the autorelease pool. When you are creating big NSData instances insinde a for loop, and those are going to the autorelease pool, all that memory sticks around for as long as the loop lasts. This is one way to optimize it:
for (int i=0; i<[self.sImages count]; i++) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSData *imageData = UIImageJPEGRepresentation([self.sImages objectAtIndex:i], 0.7);
[formData appendPartWithFileData:imageData name:@"pics[]" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
pool drain];
}
Or, if you're using LLVM3:
for (int i=0; i<[self.sImages count]; i++) {
@autoreleasepool {
NSData *imageData = UIImageJPEGRepresentation([self.sImages objectAtIndex:i], 0.7);
[formData appendPartWithFileData:imageData name:@"pics[]" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
}
}