- Hands-On Design Patterns with Swift
- Florent Vilmart Giordano Scalzo Sergio De Simone
- 125字
- 2021-07-02 14:45:06
Leaking with cycles
One common way to leak objects and their memory is to create strong references between different instances, and cut off any external references.
Let's consider the following code:
class MemoryLeak {
var ref: MemoryLeak?
init(ref: MemoryLeak) {
self.ref = ref
}
init() {
ref = self
}
}
As you can see, this is some code that you'd be unlikely to write on your own, as it doesn't have a purpose, aside from showcasing a memory leak.
The MemoryLeak class has two initializers, as follows:
- One initializer can take a reference, on to which the instance will hold
- The other initializer creates a self reference
As you can imagine, this will not bode well if we use that class in code.
推薦閱讀
- 數據要素安全流通
- Developing Mobile Games with Moai SDK
- 正則表達式必知必會
- Access 2016數據庫技術及應用
- Mockito Cookbook
- 中國數字流域
- 深入淺出 Hyperscan:高性能正則表達式算法原理與設計
- SQL應用及誤區分析
- SIEMENS數控技術應用工程師:SINUMERIK 840D-810D數控系統功能應用與維修調整教程
- 大數據與機器學習:實踐方法與行業案例
- Deep Learning with R for Beginners
- 區塊鏈應用開發指南:業務場景剖析與實戰
- SOLIDWORKS 2018中文版機械設計基礎與實例教程
- 社交網站的數據挖掘與分析(原書第2版)
- Learn Selenium