Memory & GC
Reveal answer and reasoning
Keep the owner private and expose only the intended logical view. Consider a narrow disposable lease type when ownership passes through multiple layers, but make copying and disposal semantics clear. A struct containing a reference to a lease owner can be copied; that does not automatically produce independent ownership. Prefer a design whose terminal action is idempotent at the owner and whose public API makes use after disposal fail clearly where feasible.
For an interview, compare allocating a small fresh result with pooling a large reusable workspace. The pooled workspace can be beneficial while the returned business result should own independent storage. Discuss backpressure, peak rentals, clearing policy and cancellation. A strong answer states how every path ends ownership and explains that a lower allocation rate can coexist with a higher retained heap.
Modify the portable program to reject negative and excessively large logical lengths before renting. Add a controlled processing exception and capture an independent return counter without touching the returned array. Verify the successful result remains independent of later pool reuse. If you need to test contents, inspect them during the lease or through a pool implementation designed for that test.
Review an async method that returns a task while its finally immediately returns the rented buffer. Identify whether the task has actually finished consuming the memory. Rewrite the method to await the consumer within the lease, then return in finally. Finish by drawing the distinction between reachable storage, valid ownership, exposed logical bytes and retained pool capacity.
What a strong answer covers
- Rent promises at least the requested capacity, not an exact length.
- Returning a buffer ends the lease even if the array remains reachable.
- Pooling exchanges allocation work for retained capacity and ownership complexity.
Common pitfall
Reading a returned array to test clearing, or returning before an asynchronous borrower completes.
Follow-up questions
- Who releases a rented buffer when enqueue fails?
- How do you prevent double counting active rentals and idle pool capacity?
Self-review
Choose what to revisit. These marks are your own assessment and are separate from lesson completion.