PDA

View Full Version : Releasing memory of views




anuragsolanki
Dec 24, 2008, 02:09 AM
I am having problem in releasing memories of views.

Just understand my problem in detail:
Consider I have view controllers-> view1controllers, view2controllers, view3controllers...and so on.
view2controllers is a part of view1controllers and view3controllers is part of view2controllers...
For example-
view1controllers.h
#import <UIKit/UIKit.h>

@class view2controller;

@interface view1controller : UIViewController {
view2controller *v2Controller;
}


Now I switch from view1 to view2 using
view1controller.m

if (v2controller == nil)
self.v2controller = [[view2controller alloc] initWithNibName:@"view2" bundle:[NSBundle mainBundle]];
self.view = v2controller.view


Now I want to release the memory of view1controller (or its view). How should I do it?
Similarly, I am switching between other views. As a result object allocation tends to increase and never decrease. Is there any method so that I can release the memory of last view or didReceiveMemoryWarning could help me any ways?

Just tell me if I am not clear, but please reply soon.



bnut
Dec 26, 2008, 07:53 PM
That entirely depends on how you allocated the view, but after you have removed it from usage you can probably tell it to autorelease. I'm not entirely sure of all the internal intricacies of the view hierarchy when doing this, but if you use the appropriate methods when removing it as a subview then call this, it should be fine. I haven't had a problem with this method.

l.sanjeevrao
Dec 27, 2008, 02:02 PM
Why are you going with interface builder and nibs stuff, create the views and everything from the coding itself then it doesn't make any memory problems.
here is my sample code .

HotelDetailsVIewController *elementController= [[HotelDetailsVIewController alloc] initWithIndexPath:indexPath];
[[self navigationController] pushViewController:elementController animated:YES];
[elementController release];
it never given me any problems :)