Skip to content

Commit

Permalink
Fix memory leak when using tf.layers
Browse files Browse the repository at this point in the history
Uses `weakref` so that PER_GRAPH_LAYER_NAME_UIDS doesn't prevent Graphs from being garbage collected.

Fixes tensorflow#11273
  • Loading branch information
drasmuss committed Jul 4, 2017
1 parent fc87d91 commit cc684e4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tensorflow/python/layers/base.py
Expand Up @@ -27,6 +27,7 @@
import copy
import functools
import re
import weakref

from six.moves import xrange # pylint: disable=redefined-builtin
import numpy as np
Expand Down Expand Up @@ -694,6 +695,6 @@ def _unique_layer_name(name):
```
"""
graph = ops.get_default_graph()
layer_name_uids = PER_GRAPH_LAYER_NAME_UIDS[graph]
layer_name_uids = PER_GRAPH_LAYER_NAME_UIDS[weakref.ref(graph)]
layer_name_uids[name] += 1
return name + '_' + str(layer_name_uids[name])

0 comments on commit cc684e4

Please sign in to comment.