在excel vba中调用macros后不能释放内存

我一直在这里四处查看其他问题,但无法find我的主题的解决scheme。 我注意到,每次我调用Excel中的VBA中的macros,实际上通过Microsoft脚本控制运行一些Python代码,macros使用的内存不释放,虽然我设法将例程内使用的所有内容设置为Nothing(和最终调用Python脚本中的垃圾收集器)。

代码如下:

Sub save_rt() Dim lc As MSScriptControl.ScriptControl Set lc = New MSScriptControl.ScriptControl lc.Language = "python" lc.Timeout = 50000 'in sec workingdir = Range("xmldir").Cells.Value lc.ExecuteStatement ("import pandas as pd") lc.ExecuteStatement ("import numpy as np") lc.ExecuteStatement ("import gc") myvalues = Range("icap_cf_values").Cells n_righe = UBound(myvalues) n_colonne = UBound(myvalues, 2) lc.ExecuteStatement ("myvalues = []") For i = 1 To n_righe For j = 1 To n_colonne If VarType(myvalues(i, j)) = vbString Then lc.ExecuteStatement ("myvalues.append('" + myvalues(i, j) + "')") Else lc.ExecuteStatement ("myvalues.append('" + Str(myvalues(i, j)) + "')") End If Next j Next i lc.ExecuteStatement ("myvalues = np.array([item for item in myvalues])") lc.ExecuteStatement ("myvalues = myvalues.reshape(" + Str(n_righe) + "," + Str(n_colonne) + ")") myindex = Range("icap_cf_mats").Cells lc.ExecuteStatement ("myindex = []") For Each d In myindex lc.ExecuteStatement ("myindex.append('" + d + "')") Next mycolumns = Range("icap_cf_cols").Cells lc.ExecuteStatement ("mycolumns = []") For Each d In mycolumns lc.ExecuteStatement ("mycolumns.append('" + d + "')") Next lc.ExecuteStatement ("rt = pd.DataFrame(myvalues,index=myindex,columns=mycolumns)") A = lc.Eval("rt.to_csv('" + workingdir + "\\fwd_cfs.csv')") lc.ExecuteStatement ("del rt, myvalues, mycolumns") lc.ExecuteStatement ("gc.collect()") Set myindex = Nothing Set mcolumns = Nothing Set myvalues = Nothing Set n_righe = Nothing Set n_colonne = Nothing Set A = Nothing Set workingdir = Nothing Set lc = Nothing End Sub 

我注意到,每次调用macros时,都会将Excel使用的内存增加7mb,并且不会释放它。 我不知道还有什么我在这里失踪。 希望有人能帮我解决这个问题。 谢谢