views:

27

answers:

2

hello, imagine i have a main view, in which i have a call to the "AddSubview" method, like this :

[mainView addsubview:secondView];

...in this second view, i have a searchBar, with the appropriate code to show a UIkeyboard, type some text, use this one in the app, and finally dismiss the UIkeyboard. Ok.

When this part of the program is done, i call the "AddSubview" method a second time, like this :

[secondView removeFromSuperview];
[mainView addsubview:thirdView];

When this is done, the second view disappear, and is replaced by the third one. But... The memory used by the second view is not deallocated. And, more important, the memory used by the UIkeyboard (approx. 800 Ko) is not deallocated until i quit the app, and remains active even when i replace the second view by the third view.

So, is there a way to properly deallocate the memory used by the UIkeyboard ?

(precisions : in the above code, the 3 UIviews are all subclassed in 3 class files named ManView, SecondView and ThirdView, which corresponds respectively to 3 UIviews objects in the NIB file. In each of these files i have put the "dealloc" method. But, apparently, it's never been invoked...)

+2  A: 

How you are creating secondView .. When you add subView it retains and when you remove it releases it self.

Try using Autorelease when you are creating secondView. Or Releasing secondView after removing from superview.... check if view is nil before releasing it. so if it's been released it wont crash the application.

KiranThorat
+1  A: 

As KiranThorat points out, addSubview retains the view, so make sure you release it yourself properly. Make sure your views release any subviews in the dealloc method etc.

Also, when checking for leaks on the simulator, I found that it's normal to see some UIKeyboard leaks. These are not present on the device (at least in my case).

Rengers