I have a NSURL member in my view controller. Based on user input like which button user pressed I have to dynamically get the url string and create a NSURL object.
Currently each time I am creating one NSURL object. I know this is a memory leak. Is there any way where I can change the url string value of NSRUL member without deleting its memory?
I can’t release NSURL member as the project is under @autoreleasepool.
Code snippet:
@interface myViewController : UIViewController <MyWebViewDelegate>
{
NSURL* NavigationURL;
...
}
@implementation myViewController
...
-(IBAction) LoadURL
{
if (self.NavigationURL)
{
NSURLRequest *Request = [NSURLRequest requestWithURL:NavigationURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[WebView loadRequest:Request];
}
}
- (IBAction)onHomeClick:(UIButton *)sender
{
switch (sender.tag)
{
case 101:
{
self.NavigationURL = [[NSURL alloc] initWithString:@"https://zzzqmsdb.xxxxyyyy.com/sites/pex/iPadFiles/CommAndCoord.pdf"];
[self LoadURL];
}
break;
case 102:
{
[self stopResourcesIfAlreadyLoading];
self.NavigationURL = [[NSURL alloc] initWithString:@"https://zzzqmsdb.xxxxyyyy.com/sites/pex/iPadFiles/PartCulture.pdf"];
[self LoadURL];
}
break;
}
@end
you can use [NSUrl URLWithString:] method instead of allocating it everytime.
just like this