Re: How to free memory?
- To: mathgroup at smc.vnet.net
- Subject: [mg59763] Re: How to free memory?
- From: "Wonseok Shin" <wssaca at gmail.com>
- Date: Sat, 20 Aug 2005 03:13:58 -0400 (EDT)
- References: <de46jr$r62$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Now I want to be more specific. I've read the "Garbage Collection" thread that has been going on for the past few days, and tried all solutions in there. But those couldn't resolve my problem. Here goes my code: -------------------------------------------------------------------------- In[1]:= $HistoryLength = 0; In[1]:= n1=3.5; n2=1.5; d1=0.5; d2=1.0; a = d1 + d2; In[2]:= eig[x_]:= Module[{eigVal, eigVec, T1, T2, T, k1=2Pi n1/x, k2 = 2Pi n2/x, A1, B1, A2, B2, e1, e2, h1, h2,coeff, e, de1, de2, de}, (* Calculates the matrix. *) T1={{Cos[2Pi n1 d1/x], -I Sin[2Pi n1 d1/x] /n1}, {-I Sin[2Pi n1 d1/x] n1, Cos[2Pi n1 d1/x]}}; T2={{Cos[2Pi n2 d2/x], -I Sin[2Pi n2 d2/x] /n2}, {-I Sin[2Pi n2 d2/x] n2, Cos[2Pi n2 d2/x]}}; T=T2.T1; (* Calculates the eigenvalue and eigenvector of T. *) eigVal = Eigenvalues[T][[1]]; eigVec = Eigenvectors[T][[1]]; (* Defines the equations for the eigenmodes in 0 = z = a. *) e1[z_]:= A1 Exp[I k1 z] + B1 Exp[-I k1 z]; e2[z_]:= A2 Exp[I k2 z] + B2 Exp[-I k2 z]; h1[z_]:=-n1 (A1 Exp[I k1 z] - B1 Exp[-I k1 z]); h2[z_]:=-n2 (A2 Exp[I k2 z] - B2 Exp[-I k2 z]); (* Determines the coefficients using the boundary conditions *) coeff=Solve[{{e1[0], h1[0]} == eigVec, e1[d1]==e2[0], h1[d1]==h2[0]}, {A1, B1, A2, B2 }]; (* Redefines the functions. *) DownValues[e1] = DownValues[e1] /. coeff; DownValues[e2] = DownValues[e2] /. coeff; (* Gets the eigenmode. *) e[z_ /; 0 = Mod[z, a] < d1] := eigVal^Quotient[z,a] * e1[z - a Quotient[z, a]]; e[z_ /; d1 = Mod[z, a] < a] := eigVal^Quotient[z,a] * e2[z - (a Quotient[z, a] + d1)]; (* Takes the derivatives of the eigenmode. *) de1[z_] = D[e1[z], z]; de2[z_] = D[e2[z], z]; de[z_ /; 0 = Mod[z, a] < d1] := eigVal^Quotient[z, a] * de1[z - a Quotient[z, a]]; de[z_ /; d1 = Mod[z, a] < a] := eigVal^Quotient[z, a] * de2[z - (a Quotient[z, a] + d1)]; (* Returns the eigenmode and its derivative functions. *) {e, de} ] In[3]:= eig[0.1][[2]][30] (* Checks if the function eig[x] works well. *) Out[3]= -2.3088026412307006`*^-11 - 56.97491898475945 I In[4]:= MemoryInUse[] Out[4]= 3033832 In[5]:= data = Table[eig[x], {x, 5, 10, 0.001}]; (* Generate a huge list of eigenmodes and its derivative pairs *) In[6]:= MemoryInUse[] Out[6]= 52423632 In[7]:= data=.; Clear[data]; Remove[data]; In[8]:= MemoryInUse[] Out[8]= 52425096 (* data was not released. *) -------------------------------------------------------------------------- So, why isn't data released here?