Ios 如何在应用程序中存储多个图像对象而不获取内存警告

Ios 如何在应用程序中存储多个图像对象而不获取内存警告,ios,memory-management,Ios,Memory Management,我将图像对象存储在NSMutableArray中,但在11个图像之后,我收到内存警告, 有没有比这更有效的方法不用物理存储图像 我只想在我的应用程序中保留该对象,直到用户单击按钮并在我存储图像时为止 更新 我在内部存储图像。但现在,当我在一个请求中上传服务器上的所有图像(22)时,应用程序崩溃,并显示消息“应用程序崩溃,因为内存压力” -(void)上传图像:(NSArray*)图像库 { __块NSString*tmpdocumentType=documentType; dispatch\u

我将图像对象存储在NSMutableArray中,但在11个图像之后,我收到内存警告, 有没有比这更有效的方法不用物理存储图像

我只想在我的应用程序中保留该对象,直到用户单击按钮并在我存储图像时为止

更新

我在内部存储图像。但现在,当我在一个请求中上传服务器上的所有图像(22)时,应用程序崩溃,并显示消息“应用程序崩溃,因为内存压力”

-(void)上传图像:(NSArray*)图像库
{
__块NSString*tmpdocumentType=documentType;
dispatch\u queue\u t backgroundQueue=dispatch\u queue\u create(“com.mycompany.myqueue”,0);
调度异步(后台队列^{
tmpdocumentType=[tmpdocumentType stringByAddingPercentEscapesUsingEncoding:
NSASCIIStringEncoding];
NSString*urlString=[NSString stringWithFormat:@]http://myserver.com/wsname.aspx"];
NSMutableURLRequest*request=[NSMutableUrlRequestWithURL:[NSURL URLWithString:urlString]缓存策略:NSURLRequestReloadIgnoringCacheData timeoutInterval:3600.f];
[请求设置HttpMethod:@“POST”];
NSString*boundary=@“------------------------------------14737809831466499882746641449”;
NSString*contentType=[NSString stringWithFormat:@“多部分/表单数据;边界=%@”,边界];
[请求addValue:contentType for HttpHeaderField:@“内容类型”];
NSMutableData*正文=[NSMutableData];

对于(int i=0;i将图像写入磁盘,并在阵列中存储图像的文件路径。

本地保存您的图像,然后保存所有图像的路径。不要放入阵列。这将导致内存问题,因为图像大小在内部变大。上传时应用程序崩溃。不要在内存中同时保存所有图像。在极端情况下,您只能保存一个图像e在任何给定的时间内存中。但由于我的应用程序需要,我必须在一个请求中上载所有图像。我应该怎么做。我不能一个一个地上载它。我应该添加我的代码吗。简单回答:这是不可能的。你不能随应用程序附带额外内存。你是否尝试压缩图像?实际上,我希望图像在服务器上具有完整的高度和宽度所以我不能压缩它。+1表示响应。
-(void) uploadImages:(NSArray* )imageAry
{

    __block NSString * tmpdocumentType =documentType;
    dispatch_queue_t backgroundQueue = dispatch_queue_create("com.mycompany.myqueue", 0);

    dispatch_async(backgroundQueue, ^{

        tmpdocumentType = [tmpdocumentType stringByAddingPercentEscapesUsingEncoding:
                           NSASCIIStringEncoding];
        NSString *urlString = [NSString stringWithFormat:@"http://myserver.com/wsname.aspx"];

        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:3600.f];
        [request setHTTPMethod:@"POST"];

        NSString *boundary = @"---------------------------14737809831466499882746641449";
        NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
        [request addValue:contentType forHTTPHeaderField: @"Content-Type"];

        NSMutableData *body = [NSMutableData data];

        for (int i=0; i<imageAry.count; i++) {
            [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
            [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"images[]\"; filename=\"test%i.png\"\r\n",i] dataUsingEncoding:NSUTF8StringEncoding]];
            [body appendData:[@"Content-Type: image/jpg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];

            UIImage * image = [self loadImage:[imageAry objectAtIndex:i]];

            [body appendData:UIImageJPEGRepresentation(image, 1.0)];
            [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
            image = nil;
        }

        [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

        [request setHTTPBody:body];

        NSError * error = Nil;

        NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];

        NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

        dispatch_async(dispatch_get_main_queue(), ^{
            if([returnString rangeOfString:@"Success"].location!=NSNotFound){
            }else{
            }
        });
    });
}