我在服务器上上传多张图片。当我上传大约100张图像时,内存上升到大约300 MB,即使在上传完成后,内存也不会自由。我在上传图片时使用NSData
,我的图片存储在sqlite db中。
如何减少内存峰值?
这是我的一段代码
- (void)_startUpload:(NSString *)filePath {
NSLog(@"sdf filepath : %@",filePath);
arr=[ImagesAccount getAllMovies];
for (int j=0; j<ma.count; j++) {
NSLog(@"sdf in d _startUpload ma[j] : %@",ma[j]);
[self startupuploader:ma[j]];
}
}
-(void)startupuploader:(NSString *)filePath{
@autoreleasepool {
image=YES;
NSLog(@"filepath in flicke : %@",filePath);
// JPEGData = [[[NSData alloc]initWithContentsOfFile:filePath]autorelease];
// NSLog(@"JPEGData in flicke : %@",JPEGData);
// NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:filePath]];
// NSLog(@"data in flicke : %@",data);
snapPictureButton.enabled = NO;
snapPictureDescriptionLabel.text = @"Uploading";
self.flickrRequest.sessionInfo = kUploadImageStep;
self.authorizeDescriptionLabel = nil;
self.snapPictureDescriptionLabel=nil;
self.authorizeButton=nil;
self.snapPictureButton=nil;
self.albumName=nil;
self.imageView=nil;
self.albumhome=nil;
arrs=nil;
[self.flickrRequest uploadImageStream:[NSInputStream inputStreamWithFileAtPath:filePath] suggestedFilename:@"Flickr" MIMEType:@"image/jpeg" arguments:[NSDictionary dictionaryWithObjectsAndKeys:@"0", @"is_public", nil]];
[UIApplication sharedApplication].idleTimerDisabled = YES;
[self updateUserInterface:nil];
}
}