Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

beardedpig

macrumors member
Original poster
Dec 17, 2008
57
0
I have a help web view which is displayed as a result of tapping the right nav button on a navigation control.

When the app starts the mem usage is at 10.55mb which increases to 14.00 when the help web view is displayed.

However when the help web view closes the mem usage only goes back to 13.88?

If I continue to open and close the help the mem usage slowly creeps up.

I therefore think I have not got the clean up working correctly for the help viewcontroller.

Here is the .h and .m files for the help

Code:
#import <UIKit/UIKit.h>

@interface HelpViewController : UIViewController <UIWebViewDelegate>
{
	NSString *htmlContent;
	
	UIWebView *webView;
}

// setup properties

@property (assign, nonatomic) NSString *htmlContent;
@property (assign, nonatomic) UIWebView *webView;

@end

I used asssign rather than retain as I have seen that this helps to not hold on to items when not required to do so.

Code:
#import "HelpViewController.h"
#import "KPAppDelegate.h"

@implementation HelpViewController

@synthesize htmlContent;
@synthesize webView;

-(void) viewDidLoad
{
	
	// always call the base method!
	
	[super viewDidLoad];
	
	
	CGRect webFrame = [[UIScreen mainScreen] applicationFrame];  
	
       // flush them first in case they are hanging around in memory

	[webView release];
	
	webView = nil;
	
	webView = [[[UIWebView alloc] initWithFrame:webFrame] autorelease];  
	
	webView.backgroundColor = [UIColor grayColor];  
	
	[webView loadHTMLString: htmlContent baseURL: [NSURL URLWithString: @"http://www.google.ac.uk"]];  
	
	[self.view addSubview: webView];  
	
	// set nav bar title
	
	self.title = @"Help";
	
	
	// reference the app delegate to access isPPLVisible 
	
	KPAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
	
	
	// add a right button to the navigation controller
	
	self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle: @"Done" 
																			   style: UIBarButtonItemStylePlain 
																			  target: appDelegate
																			  action: @selector(backToRoot)] autorelease];

}

- (void) didReceiveMemoryWarning 
{
	/*
	 
	 Asks the delegate for the view to scale when zooming is about to occur in the scroll view. This method is optional
	 
	 */
	
    [super didReceiveMemoryWarning]; 
}


-(void) dealloc 
{	
	// dump super
	
    [super dealloc];
}


@end


the method appDelegate.backToRoot simply pops the view off the stack.

My understanding tell me that I have this setup right but cannot understand the hold on memory plus slow creep usage

any tip please?

Thanks
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
Unless you have a good reason then the UIWebView property should be defined as (retain) and the NSString as (copy) not assign. They should both then be released in the dealloc method. If you don't explicitly retain these objects they will disappear and the pointers to them will point to garbage if you access them later on.

Your viewDidLoad method is a bit odd. The first release of webView is incorrect and shouldn't be there.

This line
Code:
	webView = [[[UIWebView alloc] initWithFrame:webFrame] autorelease];
Should be
Code:
	self.webView = [[UIWebView alloc] initWithFrame:webFrame];
And seeing as you've gone to the trouble of defining your ivars as properties you might as well use them by refering to webView as self.webView.
 

beardedpig

macrumors member
Original poster
Dec 17, 2008
57
0
Noted, thanks will make amendments and see what occurs!

Hope you can add some input on my new thread re image memory usage I am just about to add.

;-)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.