Memory & GC
Reveal answer and reasoning
Rent guarantees at least the requested number of elements, not an array of exactly that length. A consumer must receive the logical payload slice, not the whole array by default. Otherwise stale or uninitialized content outside the written range can leak into a response, and a serializer may send more bytes than intended. Initialize every element the operation will read and keep lengths explicit through the pipeline.
Return must use the same appropriate pool and occur at most once for a lease. Double return can allow multiple callers to believe they own the same array, creating data races and corrupted output. A missing return can reduce reuse and increase retained in-flight ownership. Returning a foreign array or returning while a nested async consumer is still active violates the protocol even if a simple single-threaded example appears to work.
Clearing can prevent previous contents from being exposed to future renters or remove managed references held in reference-containing arrays. For secrets, an explicit zeroing policy should target the sensitive used region while the caller still owns the buffer, using an appropriate API such as CryptographicOperations.ZeroMemory for byte secrets. A pool's clear-on-return behavior is not a universal substitute for reasoning about when and where secrets must be erased.
Clearing full rented capacity can be more expensive than clearing a small logical payload, especially when the pool returns a much larger bucket. Conversely, clearing only the used region can leave unrelated prior contents outside it, so the next consumer must still obey logical lengths. Choose the confidentiality and retention policy deliberately, measure its cost, and never read a returned buffer afterward merely to inspect whether the pool cleared it.
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.