Bug introduced in 7.0 and fixed in 9.0.0

The functions GeoDirection and GeoDistance have memory leaks. To see this, run the example functions below and watch as the Physical Memory Available in the Windows Task Manager, Performance tab, monotonically decreases with function execution.

memoryLeakGeoDirection[x_] := 
Do[GeoDirection[{RandomReal[{5, 15}], 
 RandomReal[{105, 135}]}, {RandomReal[{20, 25}], 
 RandomReal[{140, 155}]}], {x}]]



memoryLeakGeoDistance[x_] := 
Do[GeoDistance[{RandomReal[{5, 15}], 
 RandomReal[{105, 135}]}, {RandomReal[{20, 25}], 
 RandomReal[{140, 155}]}], {x}]]


If one swaps GeoDirection or GeoDistance with any of GeoDestination, GeoPosition or Log, Sin, etc. then no memory loss occurs.

I have coded a large Monte Carlo simulation using GeoDirection and GeoDistance. To run the actual simulation it is necessary to call these functions on the order of 108 to 109 times. I have upgraded the RAM from 16 GB to 32 GB, and upgraded from Windows 7 Home Premium to Windows 7 Professional, all in a failed attempt to stay ahead of the leaking memory. I am using Mathematica 64 bit.

I have tried $HistoryLength = 0 and ClearSystemCache[], without success in recovering the leaking memory.

Do you have any suggestions as to how to recover this lost memory during a running simulation?

  • $\begingroup$ It is not a memory leak, it is a memoization problem. $\endgroup$
    – FJRA
    Commented Apr 7, 2012 at 0:34
  • $\begingroup$ The example functions evaluate GeoDirection and GeoDistance with a different argument through each pass of the Do loop, and the result is not stored. And yet, memory is still lost continuously as the loop executes. However, memory is not lost in repeated execution of GeoDestination, or Log, Sin, etc. Based on this, it does not appear to me to be a meimonization problem. $\endgroup$
    – Jerry B.
    Commented Apr 7, 2012 at 2:09
  • $\begingroup$ No, the problem is in the Geo functions, they have the memoization problem. $\endgroup$
    – FJRA
    Commented Apr 7, 2012 at 3:50
  • 1
    $\begingroup$ I notice the usage with randomreal and this question mathematica.stackexchange.com/questions/3682/… has also memoryleak problems due to randomreal. Would it have the same cause? $\endgroup$
    – Lou
    Commented Apr 7, 2012 at 9:39
  • $\begingroup$ The memory loss occurs for GeoDirection and GeoDistance. If one replaces GeoDirection or GeoDistance with GeoDestination, Log, Sin, etc., with all else remaining the same, then there is no memory loss, so the memory loss is not tied to RandomReal. $\endgroup$
    – Jerry B.
    Commented Apr 7, 2012 at 17:26

1 Answer 1


Wolfram Research has prepared a patch that eliminates this memory leak. I sent a problem demo notebook to support at WRI, and WRI responded with updated versions for two GeoFunctions.mx files. Replacing the installed GeoFunctions.mx files with these updated patch versions eliminates the memory loss.

I asked WRI if I could upload this patch for others to use, and WRI requested that anyone desiring the patch files contact WRI support directly. They will then provide the patch files and the directions for their use.

Thank you for taking the time to investigate this problem and suggest possible solutions. I admire your contributions to this forum.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.