Created
February 28, 2021 06:44
-
-
Save timbaev/a6eb71e3cbd0aee53ff1e48a522ce69a to your computer and use it in GitHub Desktop.
[Weak not thread safe] Swift 4 #memorySwift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class Target {} | |
class WeakHolder { | |
weak var weak: Target? | |
} | |
for i in 0..<1000000 { | |
print(i) | |
let holder = WeakHolder() | |
holder.weak = Target() | |
dispatch_async(dispatch_get_global_queue(0, 0), { | |
let _ = holder.weak | |
}) | |
dispatch_async(dispatch_get_global_queue(0, 0), { | |
let _ = holder.weak | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment