Memory & GC
Reveal answer and reasoning
Decide whether the callee borrows a view for the duration of the returned task or takes ownership of a memory owner. Document that distinction. A caller borrowing storage must await completion before returning it to a pool; fire-and-forget work cannot silently retain the view beyond the lease. An ownership-taking API must dispose exactly once on success, failure and cancellation, including failures before work is fully accepted.
For an interview, present a parser that stores small fields from a large response in a cache. Ask whether the values must outlive the request and whether source mutation is possible. A strong design chooses copying or durable ownership at that boundary, measures the cost and avoids double counting shared backing arrays. It does not assume that using ReadOnlyMemory automatically guarantees immutability, small retained size or safe post-return access.
Change the source mutation to an index outside the twelve-byte view and explain why the view's visible contents remain unchanged while its backing ownership still includes the array. Take a slice of the copy and verify its backing length remains twelve, not the smaller logical slice length. These observations separate visibility from ownership.
Write a success/cancellation/error ownership table for an async consumer of a rented array. Mark the last possible access in each path and place Return afterward. Finally, compare a workload retaining one thousand tiny slices with one retaining one thousand tiny copies, recording payload, backing capacity and allocation throughput separately rather than reporting a single unqualified memory number.
What a strong answer covers
- A slice can retain the whole backing allocation.
- Memory<T> is not an ownership or disposal token.
- Async consumers must finish before an owned buffer is returned.
Common pitfall
Treating a short ReadOnlyMemory slice as a small independent immutable allocation.
Follow-up questions
- How can a diagnostic ArraySegment accidentally keep the old backing store alive?
- When is a small copy worth its allocation cost?
Self-review
Choose what to revisit. These marks are your own assessment and are separate from lesson completion.