Module and memory use


My question is related to this one:

I have a lot of Mathematica code in which I define functions and do many calculations. Overall, in a single session I could get to hundreds of thousands of iterations.

In order to avoid running out of memory I my functions have the form:

f =    Function[{arguments},     Module[{local vars},       do all calculations;       result= result of calc;       ClearAll[ all local vars except result];       result]]  

I also use $HistoryLength = 10

This works rather well, except for a two flaws.

First flaw

Some of my results are actually intermediate steps. This is a result of my doing some calculation, then returning a result to another function, and using this returned value to preform another calculation. Eventually, I wish to clear the first result, but how can I reference it outside the scope of the original module?

Second Flaw

Eventually the returned values of all calculations are plots. Sometimes I wish be able to use the get coordinates of curves to obtain specific values. For this I use CoordinatesToolOptions to get the desired data. My problem is that the function called using CoordinatesToolOptions needs to take as an argument several intermediate results (each matrix can take about ~200MB).

As I need them for the get coordinates, I cannot clear them. Is there a way for me to clear these matrices is still use get coordinates?


Category: scoping Time: 2016-07-31 Views: 3
Tags: memory scoping

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.154 (s). 13 q(s)