Is this a bug in Swift where any code placed inside an autoreleasepool thinks that it's not inside the loop? Is there a workaround for this rather then making a messy code by separating my code into multiple autorelease pools?
for (key, value) in dictionary {
autoreleasepool {
// Lots of allocation and lots of logic
continue // Need to continue to the next loop
// Lots of allocation and lots of logic
}
}
The argument of autoreleasepool
is a closure, so you can just early return
from the closure:
for (key, value) in dictionary {
autoreleasepool {
// Lots of allocation and lots of logic
if someCondition { return } // Need to continue to the next loop
// Lots of allocation and lots of logic
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With