Warning: This API is deprecated and will be removed in a future
version of TensorFlow after
the replacement is stable.
EagerSession.ResourceCleanupStrategy
Stay organized with collections
Save and categorize content based on your preferences.
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.
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.
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, IN_BACKGROUND
should be preferred.
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.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-02-12 UTC.
[null,null,["Last updated 2022-02-12 UTC."],[],[],null,["# EagerSession.ResourceCleanupStrategy\n\npublic static final enum **EagerSession.ResourceCleanupStrategy** \nControls how TensorFlow resources are cleaned up when they are no longer needed.\n\nAll resources allocated during an `EagerSession` are deleted when the session is\nclosed. To prevent out-of-memory errors, it is also strongly suggest to cleanup those resources\nduring the session. For example, executing n operations in a loop of m iterations will allocate\na minimum of n\\*m resources while in most cases, only resources of the last iteration are still\nbeing used.\n\n`EagerSession` instances can be notified in different ways when TensorFlow objects are\nno longer being referred, so they can proceed to the cleanup of any resources they owned.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### Inherited Methods\n\nFrom class java.lang.Enum \n\n|----------------------------------|---------------------------------------|\n| final int | compareTo(E arg0) |\n| int | compareTo(Object arg0) |\n| final boolean | equals(Object arg0) |\n| final Class\\\u003cE\\\u003e | getDeclaringClass() |\n| final int | hashCode() |\n| final String | name() |\n| final int | ordinal() |\n| String | toString() |\n| static \\\u003cT extends Enum\\\u003cT\\\u003e\\\u003e T | valueOf(Class\\\u003cT\\\u003e arg0, String arg1) |\n\nFrom class java.lang.Object \n\n|------------------|---------------------------|\n| boolean | equals(Object arg0) |\n| final Class\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| String | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nFrom interface java.lang.Comparable \n\n|--------------|-------------------------------------|\n| abstract int | compareTo(E extends Enum\\\u003cE\\\u003e arg0) |\n\nEnum Values\n-----------\n\n#### public static final EagerSession.ResourceCleanupStrategy\n**IN_BACKGROUND**\n\nMonitor and delete unused resources from a new thread running in background.\n\nThis is the most reliable approach to cleanup TensorFlow resources, at the cost of\nstarting and running an additional thread dedicated to this task. Each `EagerSession`\ninstance has its own thread, which is stopped only when the session is closed.\n\nThis strategy is used by default.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n#### public static final EagerSession.ResourceCleanupStrategy\n**ON_SAFE_POINTS**\n\nMonitor and delete unused resources from existing threads, before or after they complete\nanother task.\n\nUnused resources are released when a call to the TensorFlow library reaches a safe point\nfor cleanup. This is done synchronously and might block for a short period of time the thread\nwho triggered that call.\n\nThis strategy should be used only if, for some reasons, no additional thread should be\nallocated for cleanup. Otherwise, [IN_BACKGROUND](/api_docs/java/org/tensorflow/EagerSession.ResourceCleanupStrategy#IN_BACKGROUND) should be preferred.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n#### public static final EagerSession.ResourceCleanupStrategy\n**ON_SESSION_CLOSE**\n\nOnly delete resources when the session is closed.\n\nAll resources allocated during the session will remained in memory until the session is\nexplicitly closed (or via the traditional \\`try-with-resource\\` technique). No extra task for\nresource cleanup will be attempted.\n\nThis strategy can lead up to out-of-memory errors and its usage is not recommended, unless\nthe scope of the session is limited to execute only a small amount of operations.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]