Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Memory Leak in Mathematica?

  • To: mathgroup at
  • Subject: [mg54338] Memory Leak in Mathematica?
  • From: "M.G. Bartlett" <marshall.bartlett at>
  • Date: Sat, 19 Feb 2005 02:31:39 -0500 (EST)
  • Sender: owner-wri-mathgroup at


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
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*)
    Export[filename, dataOut, "CSV"];

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?


Marshall Bartlett

  • Prev by Date: Re: 2+ D wave equation
  • Next by Date: Re: Re: Apply on MultipleListPlot using pure functions
  • Previous by thread: Re: Elegant syntax for multiple conditional assignment?
  • Next by thread: Re: Memory Leak in Mathematica?