- 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.
推薦閱讀
- 我們都是數據控:用大數據改變商業、生活和思維方式
- 數據可視化:從小白到數據工程師的成長之路
- Microsoft SQL Server企業級平臺管理實踐
- Hadoop大數據實戰權威指南(第2版)
- Remote Usability Testing
- 智能數據時代:企業大數據戰略與實戰
- 基于OPAC日志的高校圖書館用戶信息需求與檢索行為研究
- 網站數據庫技術
- 金融商業算法建模:基于Python和SAS
- Python數據分析與挖掘實戰(第3版)
- Hadoop集群與安全
- Spark分布式處理實戰
- MySQL DBA修煉之道
- 區域云計算和大數據產業發展:浙江樣板
- Expert Python Programming(Third Edition)