# EagerSession.ResourceCleanupStrategy

public static final enum **EagerSession.ResourceCleanupStrategy** Controls how TensorFlow resources are cleaned up when they are no longer needed.

All resources allocated during an `EagerSession` are deleted when the session is
closed. To prevent out-of-memory errors, it is also strongly suggest to cleanup those resources
during the session. For example, executing n operations in a loop of m iterations will allocate
a minimum of n\*m resources while in most cases, only resources of the last iteration are still
being used.

`EagerSession` instances can be notified in different ways when TensorFlow objects are
no longer being referred, so they can proceed to the cleanup of any resources they owned.

<br />

<br />

### Inherited Methods

From class java.lang.Enum

|---|---|
| final int | compareTo(E arg0) |
| int | compareTo(Object arg0) |
| final boolean | equals(Object arg0) |
| final Class\<E\> | getDeclaringClass() |
| final int | hashCode() |
| final String | name() |
| final int | ordinal() |
| String | toString() |
| static \<T extends Enum\<T\>\> T | valueOf(Class\<T\> arg0, String arg1) |

From class java.lang.Object

|---|---|
| boolean | equals(Object arg0) |
| final Class\<?\> | getClass() |
| int | hashCode() |
| final void | notify() |
| final void | notifyAll() |
| String | toString() |
| final void | wait(long arg0, int arg1) |
| final void | wait(long arg0) |
| final void | wait() |

From interface java.lang.Comparable

|---|---|
| abstract int | compareTo(E extends Enum\<E\> arg0) |

## Enum Values

#### public static final EagerSession.ResourceCleanupStrategy
**IN_BACKGROUND**

Monitor and delete unused resources from a new thread running in background.

This is the most reliable approach to cleanup TensorFlow resources, at the cost of
starting and running an additional thread dedicated to this task. Each `EagerSession`
instance has its own thread, which is stopped only when the session is closed.

This strategy is used by default.

<br />

<br />

#### public static final EagerSession.ResourceCleanupStrategy
**ON_SAFE_POINTS**

Monitor and delete unused resources from existing threads, before or after they complete
another task.

Unused resources are released when a call to the TensorFlow library reaches a safe point
for cleanup. This is done synchronously and might block for a short period of time the thread
who triggered that call.

This strategy should be used only if, for some reasons, no additional thread should be
allocated for cleanup. Otherwise, `https://www.tensorflow.org/api_docs/java/org/tensorflow/EagerSession.ResourceCleanupStrategy#IN_BACKGROUND` should be preferred.

<br />

<br />

#### public static final EagerSession.ResourceCleanupStrategy
**ON_SESSION_CLOSE**

Only delete resources when the session is closed.

All resources allocated during the session will remained in memory until the session is
explicitly closed (or via the traditional \`try-with-resource\` technique). No extra task for
resource cleanup will be attempted.

This strategy can lead up to out-of-memory errors and its usage is not recommended, unless
the scope of the session is limited to execute only a small amount of operations.

<br />

<br />