I have checked all related questions and answers both on Stackoverflow and internet but i came to no conclusion. I am developing an ipad app, and what it does is making request to my web server download pdf file as NSData and showing it in UIWebView. The problem is even though the app(closes) segues from pdfviewer to mainviewcontroller, memory is not released thus increasing memory usage all the time. It starts with 14 mb and then every time i segue to pdfviewer from main controller it adds up. Since i'm using arc i can't release it. I am also clearing cache.
The Mainview controller.m
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"showpdf"]){
PdfViewer *pdfviewer=(PdfViewer*)[segue destinationViewController];
pdfviewer.ReportID=TheReportID;
pdfviewer.TabID=_TabID;
}
}
PdfViewer.h
@property (strong, nonatomic) IBOutlet UIWebView *MainWebView;
PdfViewer.m
-(void)viewDidLoad
{
NSURL *url = [NSURL fileURLWithPath:filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_MainWebView loadRequest:request];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"ShowMain5"]){
MainViewController *mv=(MainViewController*)[segue destinationViewController];
mv.TabID=_TabID;
}
}
-(void)dealloc{
NSLog(@"test");
}
i also tried to add UIWebview programmatically instead of IBoutlet but still couldn't solve the problem.
Programmatically( alternative )
@implementation PdfViewer
UIWebView *webview;
- (void)viewDidLoad
{
webview=[[UIWebView alloc]initWithFrame:CGRectMake(35, 35, 768,959)];
[webview loadRequest:request];
[self.view addSubview:webview];
}
When user press back button all i do is go back to mainviewcontroller modally.All segues are modal FYI.
As i understood that pdfviewer is not calling dealloc when it segues back to mainviewcontroller i checked if anyone had similar issue with viewcontrollers before and i found this question UIViewController -dealloc method not called now i think memory stays at the same level, but now it gives pdfviewer is not in the window hierarchy error.