简体   繁体   中英

UIViewController Memory Management/Issue?

I have noticed a strange behavior when adding and removing UIViewControllers I dont post for now any example,I have some view controllers that load their view from a xib and others that i create the view manually.(Do i have to declare Outlets for every element created in IB?even those that are static graphics?or does deallotion happen automatically as the allocation?) What i seem to notice is that even though i'm removing the view controllers view and then release the controller,the allocation(live bytes) in instruments doesnt seem to go down.Dealloc is being called every time.The next time i create the view controller the live bytes stay the same.As if they where previously not freed but remain cached.The thing is that i have several of them handling views that are intense? in graphics,but not all of them in the same time..and the bytes add up.It goes to about 15Mb of memory(while the app starts ta 3 and most of the time thats all that it would need).I also checked some of apples examples and i noticed sometimes the same behavior.Is it something i'm missing? Maybe its something i am doing wrong in particular,so i should post some code to examine what could be wrong? Thanks

First of all check your code for memory leaks (with leaks tool) and run "build and analyze" on your project - may be static analyzer can spot some problems.

The second thing to check is if you're releasing controller's outlets in its dealloc method: when loaded from xib files outlets are retained by default if no property defined for them or if there's a property with 'retain' attribute. So if you don't release them they must leak then I think (although instruments did not show any leaks for that case when I had similar issue)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM