Loading...
Loading...
Browse 4 real-world technical and behavioral interview questions about Closures. Review scenarios, edge cases, and architectural best practices.
A closure or delegate reference that captures its owner strongly, while the owner also holds that closure or delegate strongly, forms a cycle ARC cannot break on its own, and the fix is weak or unowned capture chosen by lifetime, not by habit. Use this IOS answer to show the decision, trade-off, and evidence rather than a memorised definition.
A closure is a function plus the scope it was created in, held by reference rather than copied. It leaks when something long-lived keeps the function alive, because everything the captured scope can reach stays reachable with it.
Python closures capture variables, not their current values, so functions created in a loop all read the same final loop binding unless you bind a value per iteration. It also connects scoping to the point an interviewer is testing.
The results reflect the list and the captured variables as they are at enumeration time, not at query construction, because a LINQ-to-objects query is an iterator holding references rather than a snapshot. Enumerating it twice runs the whole chain twice. It also connects deferred execution to the point an interviewer is testing.