Subs Function Memory Leak
6 views (last 30 days)
Show older comments
Hi, I'm running a function (for discussion purposes I'll call it myfun.m) which utilizes both "solve()" and "subs()" function. Multiple runs of the myfun causes longer and longer execution times. I believe this issue is some sort of memory leak. If I close out of Matlab, open it back up, and execute myfun, it runs at the normal speed. If I continue executing it over and over it then begins to slow down. I was running 2007, but I'm upgrading to 2010. Has this problem been fixed? Is there some sort of clear function I can use that preserves my variables but clears whatever objects are being generated by subs or solve?
2 Comments
Jan
on 20 Jul 2011
Please post any details. There is no known memory leak in SOLVE and SUBS. If there is a memory leak, it could be observed by inspecting the growing memory consumed Matlab. So you observe this?
Accepted Answer
Walter Roberson
on 20 Jul 2011
solve() uses mupad which has its own memory area. Try using
reset(symengine)
1 Comment
Walter Roberson
on 20 Jul 2011
Your code is somewhat long and complicated to go through.
If I were to go through it myself, I would be asking whether perhaps entire portions of it could be written symbolically and solve()'d, and then matlabFunction() used to convert that to MATLAB code that you could then just call with the actual numeric values.
More Answers (1)
Michael Feeney
on 20 Jul 2011
4 Comments
Walter Roberson
on 20 Jul 2011
eval() invokes the full matlab parser and JIT and threaded interpreter, and is thus a heavy-weight method of dealing with the situation.
subs(solve(...)) will look for variables in the result of solve() and will, if possible, replace them with values from the current workspace, and then will do whatever further calculations are practical. That should leave you with a symbolic number or a symbolic formula involving only constants; double() will then convert that symbolic number or constant symbolic formula in to a MATLAB-level double-precision number. The symbolic engine will handle this efficiently.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!