[Date Index] [Thread Index] [Author Index]
Clearing local variables and Memory Leaks
I had some long computations that used more and more memory. The advice from someone at WRI responding to a similar problem in an old newsgroup post was to clear local variables in Modules before leaving them. I added a Clear statement to each Module, just before my Return, where I clear every local variable except the one I am returning. Sure enough, this solved my problem. My questions: I am still puzzled as to why it would be dangerous for this behavior to be automatic? That is, once Mathematica has calculated what will be returned, what would go wrong if it cleared every local variable just before returning. If it's *not* dangerous, is there some easy way to force it to happen globally?