我的 UITableViewController 中的内存泄漏在哪里?

2024-03-01

表视图工作正常,但是当我离开视图并第二次返回时,出现内存泄漏。可能 viewDidLoad 中的某些内容不确定。

我正在运行泄漏工具并收到以下通知:

Leaked Object   #   Address Size    Responsible Library Responsible Frame
NSCFString  631 < multiple >    20192   Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8339c80   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8339af0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8339960   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x83397d0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8339640   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x83394b0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8339320   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8339190   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8339000   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8338e70   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8338ce0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8338b50   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x83389c0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8338830   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x83386a0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8338510   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8338380   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x83381f0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8338060   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8337ed0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8337d40   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8337bb0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8337a20   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x83378b0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8337720   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8337590   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8337400   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8337270   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x83370b0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8336f40   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8336dd0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8336c50   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8336ae0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8336960   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x83367e0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8336660   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x83364f0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8336360   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x83361e0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8336070   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8335ee0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8335d60   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8335be0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8335a60   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x83358f0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8335760   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8335470   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8335180   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8334e80   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8334d10   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8334b90   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8334a10   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8334890   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x83344a0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8334310   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8334180   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8333e10   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8333c80   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8333af0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8333970   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8333800   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8333670   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8323220   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8320160   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x831eef0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x831e5e0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x831d710   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8312e80   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x83119c0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x830e1c0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x83055c0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8031900   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8031770   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8031470   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8031300   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8031190   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8031010   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8030ea0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8030d20   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8030ba0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8030a20   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x80308b0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8030720   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x80305a0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x80302a0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802ffa0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802fe80   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802fb90   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802fa20   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802f8b0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802f730   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802f5c0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802f2d0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802ef10   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802ed80   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802ebd0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802ea50   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802e8e0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802cbe0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802cb40   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802c9c0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802c840   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802c6d0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802c560   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802c3e0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802c270   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802c100   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802bf90   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802bdf0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802bdd0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802bc60   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802bb90   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802b9e0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x802b870   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8028080   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x8027fe0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6f5e0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6f450   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6f150   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6efd0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6ee50   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6ece0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6eb60   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6e9e0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6e870   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6e700   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6e580   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6e400   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6e280   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6e100   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6df80   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6de00   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6dc80   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6db10   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6d930   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6d7c0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6d640   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6d420   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6d3b0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6d220   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6d090   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6cf00   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6cd70   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6cbe0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6ca50   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6c8c0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6c730   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6c5a0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6c410   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6c280   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6c0f0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6bf60   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6be10   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6bca0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6bb30   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6b9c0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6b850   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6b6e0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6b550   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6b3c0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6b230   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6b0c0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6af50   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6ae00   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6ac90   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6ab20   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6a9d0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6a880   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6a6f0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6a560   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6a3e0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6a260   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e6a0e0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e69f50   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e69de0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e69c60   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e69af0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e69980   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e69800   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e69680   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e69500   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e69380   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e69200   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e69090   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e68f20   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e68da0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e68c30   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e68ab0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e68930   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e687b0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e68640   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e684c0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e68340   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e681d0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e68040   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e67ec0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e67d40   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e67bc0   32  Foundation  -[NSCFString copyWithZone:]
NSCFString      0x4e67a50   32  Foundation  -[NSCFString copyWithZone:]

当我单击扩展视图中的第一行时,我得到:

  14 CFNetwork URLConnectionClient::_clientDidFinishLoading(URLConnectionClient::ClientConnectionEventQueue*)
  15 CFNetwork URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload(XConnectionEventInfo<XClientEvent, XClientEventParams>*, long)
  16 CFNetwork URLConnectionClient::processEvents()
  17 CFNetwork MultiplexerSource::perform()

这是代码:

#import "AddRemoteRecipientsTableViewController.h"
#import "MyManager.h"
#import "FaxRecipient.h"


@implementation AddRemoteRecipientsTableViewController

@synthesize lastIndexPath;

@synthesize delegate=_delegate;

@synthesize faxRecipient;

/*
-(IBAction) btnSave{


}
-(IBAction) btnDone{


}
 */


-(void) loadRemoteRecipients{

    activityIndicator.startAnimating;

    [remoteRecipientItems removeAllObjects];
    [[self tableView] reloadData];


    NSString * uName=[[NSUserDefaults standardUserDefaults]objectForKey:@"userNameKey"];
    NSString * pWord = [[NSUserDefaults standardUserDefaults]objectForKey:@"passwordKey"];

    NSURL *url = [NSURL URLWithString: @"https://someurl"];

    NSString *xmlString = [NSString stringWithFormat:
                           @"<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
                           "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                           "<soap:Body>"
                           "<GetContactsWithId xmlns=\"http://tempuri.org/\">"
                           "<uid>%@</uid>"
                           "<pwd>%@</pwd>"
                           "</GetContactsWithId>"
                           "</soap:Body>"
                           "</soap:Envelope>",uName,pWord
                           ];

    NSData *data = [xmlString dataUsingEncoding:NSUTF8StringEncoding];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

    //---set the headers---
    NSString *msgLength = [NSString stringWithFormat:@"%d", [xmlString length]];
    [request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request addValue:@"http://someurl" forHTTPHeaderField:@"SOAPAction"];
    [request addValue:msgLength forHTTPHeaderField:@"Content-Length"];

    //---set the HTTP method and body---
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody: data];

    if (connectionInprogress) {
        [connectionInprogress cancel];
        [connectionInprogress release];
    }


    //instantiate object to hold incoming data

    [xmlData release];

    xmlData = [[NSMutableData alloc]init];

    connectionInprogress = [[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];


}


-(void)connection:(NSURLConnection *)connection 
   didReceiveData:(NSData *)data{

    [xmlData appendData:data];
}


- (void) connectionDidFinishLoading:(NSURLConnection *)connection{


    NSXMLParser *parser = [[NSXMLParser alloc]initWithData:xmlData];
    [parser setDelegate:self];
    [parser parse];
    [parser release];

    [[self tableView] reloadData];
    activityIndicator.stopAnimating;


    [connectionInprogress release];
    connectionInprogress = nil;

    [xmlData release];
    xmlData = nil;

}


#pragma mark -
#pragma Parser Methods

-(void)parser:(NSXMLParser *)parser
didStartElement:(NSString *) elementName
 namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
   attributes:(NSDictionary *)attributeDict
{

    if ([elementName isEqual:@"ContactId"]) {
        faxRecipient =[[FaxRecipient alloc]init];
        remoteRecipientString = [[NSMutableString alloc]init]; 
    }

    else if ([elementName isEqual:@"Name"]) {
        remoteRecipientString = [[NSMutableString alloc]init]; 


    }else if ([elementName isEqual:@"Fax"]) {
        remoteRecipientString = [[NSMutableString alloc]init];
    }
    else if ([elementName isEqual:@"Company"]) {
    remoteRecipientString = [[NSMutableString alloc]init];
    }

}

-(void) parser:(NSXMLParser *)parser
foundCharacters:(NSString *)string{

    [remoteRecipientString appendString:string];

}


-(void)parser:(NSXMLParser *)parser
didEndElement:(NSString *) elementName
 namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName{


    if ([elementName isEqual:@"ContactId"]) {
        faxRecipient.contactID = remoteRecipientString;
        [remoteRecipientString release];
        remoteRecipientString = nil;
    }


    if ([elementName isEqual:@"Name"]) {
        faxRecipient.name = remoteRecipientString;
        [remoteRecipientString release];
        remoteRecipientString = nil;
    }   


    if ([elementName isEqual:@"Fax"]) {
        faxRecipient.fax = remoteRecipientString;
        [remoteRecipientString release];
        remoteRecipientString = nil;

    }

    if ([elementName isEqual:@"Company"]) {
        faxRecipient.company = remoteRecipientString;
        [remoteRecipientItems addObject:faxRecipient];
        [faxRecipient release];
        faxRecipient = nil;
        [remoteRecipientString release];
        remoteRecipientString = nil;

    }


}


-(void)connection:(NSURLConnection *)connection 
 didFailWithError:(NSError *)error{

    [connectionInprogress release];
    connectionInprogress = nil;

    [xmlData release];
    xmlData = nil;

    NSString *errorString = [NSString stringWithFormat:@"Remote Recipient Fetch Failed %@",[error localizedDescription]];

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:errorString 
                                                             delegate:nil 
                                                    cancelButtonTitle:@"OK" 
                                               destructiveButtonTitle:nil 
                                                    otherButtonTitles:nil];

    [actionSheet showInView:[[self view]window]];
    [actionSheet autorelease];

}



#pragma mark -
#pragma mark Initialization

/*
- (id)initWithStyle:(UITableViewStyle)style {
    // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/


#pragma mark -
#pragma mark View lifecycle


- (void)viewDidLoad {
    [super viewDidLoad];

    remoteRecipientItems = [[NSMutableArray alloc]init];
    remoteRecipientID = [[NSMutableArray alloc]init];

    // add activity indicator
    activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    activityIndicator.center = CGPointMake(self.view.bounds.size.width / 2.0f, self.view.bounds.size.height / 2.0f);

    activityIndicator.hidesWhenStopped = YES;
    [self.view addSubview:activityIndicator];
}



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

    [self loadRemoteRecipients];

/*  self.navigationController.toolbarHidden=NO;


    UIBarButtonItem            *saveItem;
    UIBarButtonItem            *doneItem;


    saveItem = [[ UIBarButtonItem alloc ] initWithTitle: @"Save"
                                                  style: UIBarButtonItemStyleBordered
                                                 target: self
                                                 action: @selector( btnSave ) ];



    doneItem = [[ UIBarButtonItem alloc ] initWithTitle: @"Done"
                                                  style: UIBarButtonItemStyleBordered
                                                 target: self
                                                 action: @selector( btnDone ) ];

    self.toolbarItems = nil ;

    self.toolbarItems = [ NSArray arrayWithObjects: saveItem,doneItem,nil ];

    [saveItem release];
    [doneItem release];

 */


}

/*
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
*/

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


/*  self.navigationController.toolbarHidden=YES; */
}

/*
- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/


#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [remoteRecipientItems count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"RemoteRecipientItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }




    NSUInteger row = [indexPath row];

    NSUInteger oldRow = [lastIndexPath row];

    // Configure the cell...
    FaxRecipient *faxObject= [remoteRecipientItems objectAtIndex:indexPath.row];    
    [[cell textLabel]setText:faxObject.name];
    cell.accessoryType = (row == oldRow && lastIndexPath !=nil)? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone; 

    cell.imageView.image = [UIImage imageNamed:@"contact.png"];
    return cell;
}




#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {



    int newRow = [indexPath row];
    int oldRow = (lastIndexPath !=nil)?[lastIndexPath row]:-1;

    if (newRow != oldRow) {
        UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;

        UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];

        oldCell.accessoryType = UITableViewCellAccessoryNone;

    //  lastIndexPath = indexPath;
        lastIndexPath = [indexPath retain];


    }

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

   FaxRecipient *faxObject= [remoteRecipientItems objectAtIndex:[indexPath row]];
    [self.delegate getRemoteRecipient:faxObject];
    [self.navigationController popViewControllerAnimated:YES];


}


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Relinquish ownership any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;


    remoteRecipientItems = nil;
    remoteRecipientID = nil;
    lastIndexPath = nil;
    faxRecipient = nil;




}


- (void)dealloc {

    [remoteRecipientItems release];
    [remoteRecipientID release];
    [lastIndexPath release];
    [faxRecipient release];

    [super dealloc];
}


@end

我看到您的大部分语句都已准备好泄漏,例如在 viewDidUnload 方法中,您没有正确释放任何实例成员。

您需要对您分配、初始化或保留的对象调用release。

 (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;

    [remoteRecipientItems release];
    remoteRecipientItems = nil;
    [remoteRecipientID release];
    remoteRecipientID = nil;
     ..................
    ..................

}

建议你花一些时间阅读内存管理编程指南 http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我的 UITableViewController 中的内存泄漏在哪里? 的相关文章

  • iOS 使用 NSColor 与 UIColor?

    有什么区别UIColor and NSColor 什么时候会使用每一种 我碰到NSColor在试图弄清楚的同时UIColor用于 iOS 中的属性字符串 我理解使用UIColor对于 UIKit 等 但我不认为NSColor对于这种事情确实
  • 进入后台时 Alamofire 请求卡住?

    我正在使用 Alamofire 调用 Web 服务 该服务需要相当长的时间才能加载 如果应用程序进入后台 当我返回应用程序时 我会被加载程序卡住 我想这是因为调用永远不会向我的完成处理程序返回任何内容 我该如何解决这个问题 您可以使用后台抓
  • iOS WKWebView 处理文件下载

    我面临以下问题 在 Web 界面中 文件下载是通过锚标记触发的 如下所示 a href bla blabla a 虽然 Safari 浏览器可以处理此请求并打开一个对话框来处理文件 但 WKWebView 将此视为普通链接并且不对其执行任何
  • iPhone 3GS 上的 ARM 与 Thumb 性能比较,非浮点代码

    我想知道是否有人有关于 iPhone 3GS 上 ARM 与 Thumb 代码性能的硬性数据 特别是对于非浮点 VFP 或 NEON 代码 我知道 Thumb 模式下的浮点性能问题 更大的 ARM 指令的额外代码大小是否会在某个时刻成为性能
  • 如何在 iOS 中将 Firebase 对象持久保存到磁盘?

    看起来Firebase http www firebase comiOS 实现不支持客户端模型的离线缓存 这在实践中意味着 对于需要身份验证的 Firebase 应用程序 您需要首先进行身份验证并等待 Firebase 完成登录 检查用户身
  • 在回调函数中调用目标c函数

    如何在回调函数中调用目标c函数 回调函数 static OSStatus inputRenderCallback void inRefCon AudioUnitRenderActionFlags ioActionFlags const Au
  • 使用特定的 url 启动 UIWebview

    我目前有一个包含四个按钮的视图 并且希望能够启动 UIWebview 并为每个不同的按钮提供特定的 url 我目前可以使用 url 从外部启动 safari 我知道我可以使用代码在每个按钮中显示 UIWebview 并且可以在 UIWebv
  • 如何组合两个 SwiftyJSON 对象

    我有一个 swiftyJSON 对象 例如 location http img http commentCount 0 timestamp 1432460217550 我希望能够向其附加另一个 swiftyJSON 对象 使其看起来像 lo
  • 用于具有转换的非导航应用程序的视图控制器/NIB 架构?

    我正在修补一个 iPad 应用程序 就像许多 iPad 应用程序一样 它不使用 UINavigation 根视图控制系统 因此我没有每个应用程序 视图 的自然所有权 我基本上有两个基本视图 文档列表视图和文档编辑视图 我正在使用 UIVie
  • 保存来自 TrueDepth 相机的深度图像

    我正在尝试保存 iPhone X TrueDepth 相机的深度图像 使用AVCam照片滤镜 https developer apple com library content samplecode AVCamPhotoFilter Lis
  • 如何解决 iOS 6 SDK 中的 hidesBottomBarWhenPushed 行为异常的问题?

    我遇到了中描述的相同问题这个 OpenRadar 问题 http www openradar me 14670329 正如那里所说 摘要 UIViewController的hidesBottomBarWhenPushed属性 对于使用 iO
  • 在情节提要中将 Segue 拖至自身

    我想将一个 Segue 从我的视图控制器拖到其自身 所以我可以推送该特定视图控制器的 无限 实例 我知道如何在代码中执行此操作 即以编程方式实例化视图控制器 但是 我想尽可能使用 segues 我发现了一些在故事板中进行自我延续的 技巧 但
  • 将 Armadillo C++ 库导入 Xcode

    我是 Mac 用户 正在尝试安装和导入 C Armadillo 库 以下是我到目前为止所采取的步骤 1 我从其网站下载了犰狳库 2 我仔细阅读了下载文件中的 Readme txt 文件 解释了如何安装它 3 我使用CMake将犰狳下载文件制
  • NSURLCache 不缓存

    我正在使用 Xcode 6 1 6A1030 iOS7 和 iOS8 模拟器 NSURLCache 似乎没有缓存任何东西 我使用 Cache Control 标头 我的服务器返回带有 max age 6000 的 Cache Control
  • 如何检索 iPhone 的区域设置

    我用谷歌搜索过它 但令我有点惊讶的是我找不到它 我只想访问设备配置的区域设置 我试图找到如何列出所有系统属性 以防我能在那里找到区域设置 但甚至找不到如何做到这一点 我知道 认为 我之前检索过系统属性 但我也记得在谷歌搜索时找到该信息并不容
  • iPhone SDK中的短信正文

    我需要从我的 iPhone 应用程序发送短信 SMS 的正文是以编程方式创建的 因此 当我点击按钮时 短信应用程序应该打开 并在其中预先输入我的消息 有人知道怎么做吗 需要帮忙 提前致谢 世宾 您无法设置短信正文 根据官方 SDK 您可以从
  • 当 ViewController 从 UIStoryboard 实例化时,isMemberOfClass 返回 no

    我有一个 OCUnit 测试类 PatientTestViewControllerTests 下面是界面 interface PatientTestViewControllerTests SenTestCase property nonat
  • 下载进度条在 iOS 企业发行版中没有改变进度

    我正在通过企业分发开发和分发 iPad 应用程序 它们下载并执行良好 因此一切正常 Web 链接 ipa 文件 plist 文件 配置 问题 是 当用户单击链接进行下载时 iPad 中显示下载进度的进度条显示 正在等待 但却是空的并且永远不
  • 如何将自定义 C 代码放入 SwiftPM 包中?

    我正在尝试将 C 代码打包到 Swift 模块中 我们称之为CModule 一旦我将其放入项目的基本文件夹中 Swift模块 并配置了搜索路径 我可以在 Swift 文件中自动完成工作 并检测错误 警告 问题是 导入时它无法识别该模块 并且
  • 游戏中心邀请处理程序,它属于哪里?

    我已经搜索了该网站并发现了这个 GameCenter 邀请处理程序 https stackoverflow com questions 4639284 gamecenter invitation handler He says 正如文档中所

随机推荐