Skip to content

Instantly share code, notes, and snippets.

@timbaev
Created February 28, 2021 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timbaev/a6eb71e3cbd0aee53ff1e48a522ce69a to your computer and use it in GitHub Desktop.
Save timbaev/a6eb71e3cbd0aee53ff1e48a522ce69a to your computer and use it in GitHub Desktop.
[Weak not thread safe] Swift 4 #memorySwift
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