Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Memory leak of TString.tensorOf(Shape shape, DataBuffer<String> data)

Ouverte
#371 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
java

Piste de recherche

Commencez par exécuter la reproduction Java fournie autour de TString.tensorOf(Shape, DataBuffer) et de DataBuffers.ofObjects(result), puis examinez comment TString.close() libère les ressources. Comparez le comportement de la mémoire pour les cas de 4, 8192 et 65536 itérations. Le travail est considéré comme terminé lorsque les instances de TString créées et fermées à répétition n’entraînent plus d’augmentation inattendue de l’utilisation mémoire.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04 x86_64): macOS 11.5.2
  • TensorFlow installed from (source or binary): Binary
  • TensorFlow version (use command below): 2.5
  • Java version (i.e., the output of java -version): Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)
  • Java command line flags (e.g., GC parameters): -ea
  • Python version (if transferring a model trained in Python): 3.7
  • Bazel version (if compiling from source): N/A
  • GCC/Compiler version (if compiling from source): N/A
  • CUDA/cuDNN version: N/A
  • GPU model and memory: N/A
  • Tensorflow Java version: 0.3.2

Describe the current behavior
When I create and destroy TString instances repeatedly in a for loop, memory usage grows. In my production environment, where a TF model is served by a java service, it would cause memory usage alert after processing certain amount of requests.

Describe the expected behavior
Memory usage should not grow since created TString instances are closed in each iteration.

Code to reproduce the issue

    @Test
    void testPerformance() throws Exception {
        // Some code to load a model but never used it in this test case. Otherwise, the following code would exit randomly. See https://github.com/tensorflow/java/issues/370 .
        final String[] result = new String[] {"a", "b", "c", "d", "e", "f", "g", "h", "i", "c", "c", "c"};
        for (int i = 0; i < 65536; ++i) {
            try (final TString tstring = TString.tensorOf(Shape.of(1, result.length), DataBuffers.ofObjects(result))) {
               // this block is empty.
            }
        }
  }

Other info / logs
4 iterations
image
8192 iterations
image
65536 iterations
image

The above are IntelliJ IDEA's memory profiling screenshots. The differences are as following:

  • The first was recorded when the for loop runs 4 iterations (; i < 4; ...). The TString.tensorOf calls only use 2% memory of its parent call.
  • The second wass recorded when the for loop runs 8192 iterations (; i < 8192; ...). The TString.tensorOf calls use 49.05% memory of its parent call.
  • The third was recorded when the for loop runs 65536 iterations (; i < 65536; ...). The TString.tensorOf calls use up to 83.56% memory of its parent call.
Langage dominant
Java
Étoiles
928
Forks
227
Métriques de merge des PR
Aucune PR mergée en 30 j

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de tensorflow/java

Toutes les issues de tensorflow/java

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.