4 Resource Release

“I saw the angel in the marble and carved until I set him free.”

Michelangelo Buonarroti

Timely release of resources that are no longer being used is essential in maintaining system stability and avoiding cases of resource exhaustion. Optimizing the release of resources is beneficial, as system performance and scalability depend directly on it. If reusable resources have to be acquired repeatedly, overhead is incurred. If the resources are not freed when no longer needed, it can lead to resource starvation. This in turn can lead to system instability and degrade scalability of the system.

Releasing resources explicitly can be tedious and sometimes error-prone. Both the Leasing (149) pattern and the Evictor (168) pattern address resource release by ensuring that acquired reusable resources are released in a timely manner. The Leasing pattern simplifies resource release by associating time-based leases with resources when they are acquired. The resources are automatically released when the leases expire and are not renewed. The Evictor pattern deals with determining when to release resources and which resources to release. The patterns together help to optimize the number of acquired resources at any point in time.

Leasing

The Leasing pattern simplifies resource release by associating time-based leases with resources when they are acquired. The resources are automatically released when the leases expire and are not renewed.

Example

Consider a system consisting ...

Get Pattern-Oriented Software Architecture Volume 3: Patterns for Resource Management now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.