1 tf.placeholder 是不申請內存的,它指向的feed_dict={input1:rand_array} 中rand_array的內存.
比如下面的代碼
import numpy as np
import tensorflow as tf
input1 = tf.placeholder(tf.int8, [4*1024, 1024, 1024])
input2 = tf.placeholder(tf.int8, [4*1024, 1024, 1024])
rand_array = np.random.randint(0,127,[4*1024,1024,1024],dtype=np.int8)
with tf.Session() as sess:
sess.run(input1, feed_dict={input1:rand_array})
通過task manager 可以看到總共申請了4G 的內存。 rand_array 還保留在variable_explore中
如果之後
rand_array = 1
則 內存全部釋放掉 python 這個線程之後1百多mb。
說明 sess()運行結束後釋放了內存.