EagerSession.ResourceCleanupStrategy
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
TensorFlow 리소스가 더 이상 필요하지 않을 때 정리하는 방법을 제어합니다.
EagerSession
중에 할당된 모든 리소스는 세션이 닫힐 때 삭제됩니다. 메모리 부족 오류를 방지하려면 세션 중에 해당 리소스를 정리하는 것이 좋습니다. 예를 들어, 반복 반복에서 n 작업을 실행하면 최소 n*m 리소스가 할당되지만 대부분의 경우 마지막 반복의 리소스만 계속 사용됩니다.
EagerSession
인스턴스는 TensorFlow 객체가 더 이상 참조되지 않을 때 다양한 방식으로 알림을 받을 수 있으므로 소유한 모든 리소스를 정리할 수 있습니다.
상속된 메서드
클래스 java.lang.Enum에서 최종 정수 | 비교 (E arg0) |
정수 | CompareTo (객체 arg0) |
최종 부울 | 같음 (개체 arg0) |
최종 클래스<E> | getDeclaringClass () |
최종 정수 | 해시 코드 () |
최종 문자열 | 이름 () |
최종 정수 | 서수 () |
끈 | toString () |
static <T는 Enum<T>> T를 확장합니다. | valueOf (클래스<T> arg0, 문자열 arg1) |
java.lang.Object 클래스에서 부울 | 같음 (개체 arg0) |
마지막 수업<?> | getClass () |
정수 | 해시 코드 () |
최종 무효 | 알림 () |
최종 무효 | 통지모두 () |
끈 | toString () |
최종 무효 | 대기 (long arg0, int arg1) |
최종 무효 | 기다리세요 (긴 arg0) |
최종 무효 | 기다리다 () |
인터페이스 java.lang.Comparable에서 추상 정수 | CompareTo (E는 Enum<E> arg0을 확장함) |
열거형 값
공개 정적 최종 EagerSession.ResourceCleanupStrategy IN_BACKGROUND
백그라운드에서 실행되는 새 스레드에서 사용되지 않는 리소스를 모니터링하고 삭제합니다.
이는 이 작업 전용 스레드를 추가로 시작하고 실행하는 비용으로 TensorFlow 리소스를 정리하는 가장 안정적인 접근 방식입니다. 각 EagerSession
인스턴스에는 세션이 닫힐 때만 중지되는 자체 스레드가 있습니다.
이 전략은 기본적으로 사용됩니다.
공개 정적 최종 EagerSession.ResourceCleanupStrategy ON_SAFE_POINTS
다른 작업을 완료하기 전이나 후에 기존 스레드에서 사용되지 않는 리소스를 모니터링하고 삭제합니다.
TensorFlow 라이브러리에 대한 호출이 정리를 위한 안전한 지점에 도달하면 사용되지 않은 리소스가 해제됩니다. 이는 동기적으로 수행되며 해당 호출을 트리거한 스레드를 짧은 시간 동안 차단할 수 있습니다.
이 전략은 어떤 이유로 인해 정리를 위해 추가 스레드를 할당하지 말아야 하는 경우에만 사용해야 합니다. 그렇지 않으면 IN_BACKGROUND
선호됩니다.
공개 정적 최종 EagerSession.ResourceCleanupStrategy ON_SESSION_CLOSE
세션이 닫힐 때만 리소스를 삭제하세요.
세션 중에 할당된 모든 리소스는 세션이 명시적으로 닫힐 때까지(또는 전통적인 'try-with-resource' 기술을 통해) 메모리에 유지됩니다. 리소스 정리를 위한 추가 작업은 시도되지 않습니다.
이 전략은 메모리 부족 오류로 이어질 수 있으며 세션 범위가 소량의 작업만 실행하도록 제한되지 않는 한 사용하지 않는 것이 좋습니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 크리에이티브 커먼즈 저작자 표시 라이선스 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다. 일부 콘텐츠에는 Numpy 라이선스가 부여됩니다.
최종 업데이트: 2025-07-27(UTC)
[null,null,["최종 업데이트: 2025-07-27(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](/versions/r2.13/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"]]