2015-01-31 2 views
0

작은 테스트 기능이 있으며 실행 시간 1 시간 후에 메모리 할당 문제와 메모리 경고가 표시됩니다. NSData * data = [NSURLConnection sendSynchronousRequest : req returningResponse : & 응답 오류 : & 오류 1]; 호출에서 문제가 발생했습니다.메모리 누수 호출 싱크 방법

아래 코드는 제 코드입니다. 도움을 주시면 감사하겠습니다.

Here is my app stat after 1 hour running: 
Low: 712Kb, High 275.4 MB, Durarion 1 hour 26 min 

2015-01-31 14:38:11.811 testMem[5268:546116] Received memory warning. 
2015-01-31 14:38:16.836 testMem[5268:546116] Received memory warning. 
2015-01-31 14:38:24.573 testMem[5268:546116] Received memory warning. 
2015-01-31 14:38:29.850 testMem[5268:546116] Received memory warning. 
2015-01-31 14:38:34.779 testMem[5268:546116] Received memory warning. 
2015-01-31 14:38:40.058 testMem[5268:546116] Received memory warning. 
2015-01-31 14:38:44.922 testMem[5268:546116] Received memory warning. 

MainView.m

#import "ViewController.h" 
#import "global.h" 


#import "ServiceSvc.h" 
#import "ClsTickets.h" 

@interface ViewController() 
{ 
    NSTimer* g_BACKUPTIMER; 
} 
@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 


} 

- (void) viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    g_BACKUPTIMER = [NSTimer scheduledTimerWithTimeInterval:.4 target:self selector:@selector(runBackupProcess) userInfo:nil repeats:YES]; 

} 
-(void)runBackupProcess 
{ 
    if (stopTimer == 0) 
    { 
     [NSThread detachNewThreadSelector: @selector(runtest) toTarget:self withObject:nil]; 
    } 
    else 
    { 

    } 
} 



- (void) runtest 
{ 
    @autoreleasepool { 
     @try 
     { 

      ServiceSvc_DoAdminUnitIpad *req2 = [[ServiceSvc_DoAdminUnitIpad alloc] init]; 
      req2.UnitDesc = @"Unit 6"; 
      req2.CustomerID = @"800014"; 
      req2.MachineID = nil; 
      req2.UnitID = @"1"; 
      req2.GPSData = nil; 

      ServiceSynchronous* synCrhous = [[ServiceSynchronous alloc] init]; 

      NSData* data = [synCrhous makeSynchrounousCall:req2]; 

      data = nil; 
      req2 = nil; 

     } 
     @catch (NSException *exception) 
     { 
     } 
     @finally 
     { 
     } 
    } // end auto 

} 




- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 

ServiceSvc.m

@implementation ServiceSynchronous 
-(NSData*) makeSynchrounousCall:(ServiceSvc_DoAdminUnitIpad*) parameters 
{ 
    NSURLResponse* response = nil; 
    NSError* error1 = nil; 


    NSString *operationXMLString = @"<?xml version=\"1.0\"?> <soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:ServiceSvc=\"https://xxx/service.asmx\" xsl:version=\"1.0\"> <soap:Body> <ServiceSvc:DoAdminUnitIpad> <ServiceSvc:UnitID>1</ServiceSvc:UnitID> <ServiceSvc:UnitDesc>Unit 6</ServiceSvc:UnitDesc> <ServiceSvc:CustomerID>800014</ServiceSvc:CustomerID> </ServiceSvc:DoAdminUnitIpad> </soap:Body> </soap:Envelope>"; 
    NSString *msgLength = [NSString stringWithFormat:@"%d", 
          [operationXMLString length]]; 

    NSMutableURLRequest * req = [[NSMutableURLRequest alloc] init]; 
    [req setURL:[NSURL URLWithString:@"https://xxx/service.asmx"]]; 
    [req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
    [req addValue:@"http://tempuri.org/webservice-name/method-name" forHTTPHeaderField:@"SOAPAction"]; 
    [req addValue:msgLength forHTTPHeaderField:@"Content-Length"]; 
    [req setHTTPMethod:@"POST"]; 

    [req setHTTPBody:[operationXMLString dataUsingEncoding:NSUTF8StringEncoding]]; 

    NSData* data = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error1]; 
    [[NSURLCache sharedURLCache] removeCachedResponseForRequest:req]; 

    if (error1 == nil) 
    { 

    } 
    else 
    { 

    } 

    operationXMLString = nil; 
    req = nil; 

    response = nil; 
    return data; 
} 
@end 


@implementation ServiceSvc_DoAdminUnitIpad 
- (id)init 
{ 
    if((self = [super init])) { 
     UnitID = 0; 
     UnitDesc = 0; 
     CustomerID = 0; 
     MachineID = 0; 
     GPSData = 0; 
    } 

    return self; 
} 

- (NSString *)nsPrefix 
{ 
    return @"ServiceSvc"; 
} 
- (xmlNodePtr)xmlNodeForDoc:(xmlDocPtr)doc elementName:(NSString *)elName elementNSPrefix:(NSString *)elNSPrefix 
{ 

} 
/* elements */ 
@synthesize UnitID; 
@synthesize UnitDesc; 
@synthesize CustomerID; 
@synthesize MachineID; 
@synthesize GPSData; 
/* attributes */ 
- (NSDictionary *)attributes 
{ 
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary]; 

    return attributes; 
} 
+ (ServiceSvc_DoAdminUnitIpad *)deserializeNode:(xmlNodePtr)cur 
{ 
    ServiceSvc_DoAdminUnitIpad *newObject = [ServiceSvc_DoAdminUnitIpad new]; 

    [newObject deserializeAttributesFromNode:cur]; 
    [newObject deserializeElementsFromNode:cur]; 

    return newObject; 
} 
- (void)deserializeAttributesFromNode:(xmlNodePtr)cur 
{ 
} 
- (void)deserializeElementsFromNode:(xmlNodePtr)cur 
{ 



} 
@end 

몇 가지 조사 후 ServiceSvc.h

@interface ServiceSvc_DoAdminUnitIpad : NSObject { 

/* elements */ 
    NSString * UnitID; 
    NSString * UnitDesc; 
    NSString * CustomerID; 
    NSString * MachineID; 
    NSString * GPSData; 
/* attributes */ 
} 
- (NSString *)nsPrefix; 
- (xmlNodePtr)xmlNodeForDoc:(xmlDocPtr)doc elementName:(NSString *)elName elementNSPrefix:(NSString *)elNSPrefix; 
- (void)addAttributesToNode:(xmlNodePtr)node; 
- (void)addElementsToNode:(xmlNodePtr)node; 
+ (ServiceSvc_DoAdminUnitIpad *)deserializeNode:(xmlNodePtr)cur; 
- (void)deserializeAttributesFromNode:(xmlNodePtr)cur; 
- (void)deserializeElementsFromNode:(xmlNodePtr)cur; 
/* elements */ 
@property (retain) NSString * UnitID; 
@property (retain) NSString * UnitDesc; 
@property (retain) NSString * CustomerID; 
@property (retain) NSString * MachineID; 
@property (retain) NSString * GPSData; 
/* attributes */ 
- (NSDictionary *)attributes; 
@end 

@interface ServiceSynchronous : NSObject { 
} 
- (NSData*) makeSynchrounousCall:(ServiceSvc_DoAdminUnitIpad*) parameters; 
@end 
+0

-------------------------------------------- – tony

답변

0

, 나는 애플의있는 NSURLConnection는 결론에 도달했다 문제. 문제는 2008 년에보고되었고 Apple은 그것을 인정했지만 현재는 2015 년이며 문제는 여전히 있습니다. 비동기 호출로 전환했으며 메모리 할당 문제는 여전히 있지만 크기는 작습니다. 애플의 괴짜들은 농담이다.