Group Abstract Group Abstract

Message Boards Message Boards

1
|
16.1K Views
|
11 Replies
|
3 Total Likes
View groups...
Share
Share this post:

What options does Mathematica have for memory management?

Posted 11 years ago

Hey there, community,

I am having some issues with Mathematica's kernel seemingly leaking memory over time.

What I have tried so far is to start my notebook with the following commands:

Remove["Global`*"];
ClearSystemCache[];
$HistoryLength = 0;
MemoryInUse[]

However, when I run my notebook several times, MemoryInUse reports an increase of ~12 MB in memory consumption each time.

So, is there some generic solution that I'm missing here? If not, then I'll have to look into creating an example notebook, but I'll start with asking for a general solution.

If it helps, I'm working with NDSolve using the new FEM toolbox, so it's of course possible (though hopefully unlikely) that there's some memory issue with the FEM implementation.

-Jonatan

EDIT: I forgot to mention this, but simply killing the kernel isn't an option. In fact, I'd like to avoid even having to call Remove["Global`*"], since in this case the memory consumed by those variables is negligible -- Mathematica is using memory somewhere else, I just can't figure out where.

POSTED BY: Jonatan Lehtonen
11 Replies

Reference counting, when the reference count goes to zero, returns the memory segment(s) to a heap. The heap, itself, does garbage collection much like one defragments a disk. Usually memory is pointed to by handles that point to another set of pointers into memory. When a handle is locked memory may be moved to defragment the heap. At any rate, garbage collection is probably not an issue. But if the programmers are not disciplined about having reference counts for every object and ensuring the lifecycle of the object is not open-ended this can cause the leaks to appear.

POSTED BY: Jeffrey Saltzman
Posted 10 years ago

Pardon me for interjecting this but isn't that how garbage collection is supposed to work? Memory will keep filling until the trigger point for garbage collection is reached and then the operating system will clear up memory and defragment memory. I am a little bit lazy here but I have a book on managed code I think that is the way it is designed. I think the GC has to step through memory and look for unreferenced memory locations before it can free up memory. The garbage collector does not continually remove items from memory because it is too cpu intensive. --- I could be wrong---

POSTED BY: RICHARD WEIMER

Mathematica uses reference counting rather than garbage collection in order to determine what memory can be recycled.

POSTED BY: Daniel Lichtblau
Attachments:
POSTED BY: Jeffrey Saltzman
POSTED BY: Jonatan Lehtonen
POSTED BY: Daniel Lichtblau

Thank you for confirming this, I've contacted support now.

POSTED BY: Jonatan Lehtonen

You can add Share[] to your list to see if it has any effect....

POSTED BY: David Reiss
POSTED BY: Jonatan Lehtonen

You might want to send an example to support@wolfram.com. The description you give is not inconsistent with an actual memory leak).(I use a double negative by intent; I do not want to give the impression that this is necessarily indicative of a bug, just that it is a possibility).

POSTED BY: Daniel Lichtblau

Thanks, that's probably my next step unless someone points out something I've missed.

POSTED BY: Jonatan Lehtonen
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard