Question

I use MathLink to send and receive independent mma expressions from a C++ application as strings.

std::string expression[N];
// ...
for(int i = 0; i < N; ++i) {
    MLPutFunction(l, "EnterTextPacket", 1);
    MLPutString(l, expression[i].c_str());
    MLEndPacket(l);

    // Check Packet ...

    const char* result;
    MLGetString(l, &result);

    // process result ...

    MLDisownString(l, result);
}

I would expect that MLDisownString frees the used memory except that it doesn't.

Any ideas?

Was it helpful?

Solution

Ok. Posting this as an answer, because I believe the odds you are using version 5 or below are pretty low:

`As of Version 6.0, MLDisownString() has been superseded by MLReleaseString()`

Check it here

OTHER TIPS

First of all, I should point out such parameter as $HistoryLength. Setting it to zero often allows to reduce memory requirements considerably:

$HistoryLength = 0

At the same time, it is known problem with the MathKernel process that it accumulates system memory in long computations and does not release it.

The only way to ultimately solve the problem it to restart the kernel when it takes too much memory or when the amount of available free physical memory becomes too small. This task can be automatized.


If you have not tried Mathematica 8 yet, it may be worth a try, since, according to Oliver Ruebenkoenig:

For version 8 the memory allocator has been rewritten and improved.

(What a small sentence for such a huge endeavor and such a fine execution)

But I have not tried the version 8 yet and cannot say anything on it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top