- iOS Programming Cookbook
- Hossam Ghareeb
- 206字
- 2021-07-09 18:29:44
How it works...
We have started our example by creating two classes, Person and Dog. The Person class has one-to-many relation to the Dog class via the property array dogs. The Dog class has one-to-one relation to class Person via the property owner. Everything looks good, and it works fine if you tested, but unfortunately we did a terrible mistake. We have a retain cycle problem here, which means we have two objects in memory; each one has a strong reference to the other. This leads to a cycle that prevents both of them from being deallocated from memory.
This problem is a common problem in iOS, and not all developers note it while coding. We call it as parent-child relation. Parent (in our case, it's the Person class) should always have a strong reference to child (the Dog class); child should always have a weak reference to the parent. Child doesn't need to have strong reference to parent, as child should never exit when parent is deallocated from memory.
To solve such a problem, you have to break the cycle by marking one of these references as weak. In step 2, we see how we solved the problem by marking the property owner as weak.
- Windows Server 2019 Cookbook
- Modern Web Testing with TestCafe
- Windows Vista基礎與應用精品教程
- Linux系統文件安全實戰全攻略
- UNIX操作系統設計
- Ganglia系統監控
- SharePoint 2013 應用開發實戰
- 混沌工程:復雜系統韌性實現之道
- jQuery UI Cookbook
- Vim 8文本處理實戰
- Learning BeagleBone
- 從實踐中學習Windows滲透測試
- Office 365 User Guide
- 電腦辦公(Windows 10 + Office 2016)入門與提高(超值版)
- Java EE 7 Developer Handbook