Memory Leak in Mathematica?
- To: mathgroup at smc.vnet.net
- Subject: [mg54338] Memory Leak in Mathematica?
- From: "M.G. Bartlett" <marshall.bartlett at gmail.com>
- Date: Sat, 19 Feb 2005 02:31:39 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Folks, Has anyone ever experienced a problem with Mathematica leaking memory? I am running 5.1 on WindowsXP and have run into a memory issue from the following code which essentially just steps through a directory of files, reading each in and doing some processing on the data, then writing to a new location: (*Set a read directory and a write directory, get filenames to process*) oldDirectory = Directory[]; newDirectory = "D:\\NewDirectory"; currentFileNames = FileNames["*",{oldDirectory}]; processFile[filename_] := Module[{dataIn, dataOut}, (*Load the file*) dataIn = Import[filename, "CSV"]; (*Do some work on the data in the file*) dataOut = Map[Drop[#, -2] &, dataIn]; (*Write to the newDirectory*) SetDirectory[newDirectory]; Export[filename, dataOut, "CSV"]; SetDirectory[oldDirectory]; ] Map[processFile, currentFileNames]; My problem is that when the number of files to be read in is large, Mathematica quits mid-process and returns an "Out of Memory" message. However, as I read the code it should never be using more memory then that required to hold a single file in memory. As I watch Mathematica's memory usage as the process runs, however, it slowly consumes more and more of the machine's resources. Am I missing something in the code that would cause Mathematica to hold on to memory or is this a bug in Mathematica? Thanks, Marshall Bartlett