2

i am using addSubView method to add views. Did any alternative methods are there for viewWillDisappear? viewWillDisappear is not firing. I want to release all allocated objects when the current view get dissapear. Currently i am using dealloc method to do this. But dealloc method is firing not quickly. Since i am getting memory warings and sometimes the my app may crash itself. The main problem is with voice files.

Vipin Vijay
  • 393
  • 5
  • 21
  • Where do you think viewWillDisappear should be called and why? Are you navigating away from your view controller by navigation controller, tab bar controller, presenting another view controller modally or doing something else? – Filip Radelic Sep 02 '11 at 07:42

3 Answers3

1

addSubview/removeFromSuperview (these methods relate with views not view controllers) doesnt call viewWillAppear/viewWillDisappear methods. You should write release object code in dealloc() itself.
removeFromSuperview should call dealloc().

Mahesh
  • 662
  • 2
  • 11
  • 30
  • fixed it my self by sending this message to VC manually when view animation begins. Code: [myViewController viewWillAppear:YES]; – Vipin Vijay Sep 02 '11 at 11:22
0

You can try to release objects in method viewDidDisappear. Then you won't wait for firing method dealloc.

Also in method viewDidDisappear you can try to remove all subviews from superview (that will call viewWillDisappear to all subviews):

NSArray *subviews = [self.view subviews];
for (UIView *view in subviews)
    [view removeFromSuperview];
Nekto
  • 17,837
  • 1
  • 55
  • 65
  • Since i am using addSubView viewDidDisappear, viewWillDisappear, will not work. I Done this using Code: [myViewController viewWillAppear:YES]; – Vipin Vijay Sep 02 '11 at 11:25
0

release objects in viewDidUnload/viewDidDisappear and set to nil in dealloc

this might work, but you should surely look why viewWillDisappear is not called.

Nilesh Ukey
  • 5,488
  • 3
  • 20
  • 22
  • There's no point in releasing "objects" you set to nil, as they are not objects, they are pointers to nil, and you can't release nil. – Filip Radelic Sep 02 '11 at 07:35