MatLab have memory leaks?

5 views (last 30 days)
Lucas
Lucas on 2 Jul 2012
When I open MatLab at the beginning it takes up less than 200k in memory. When I open a Simulink model it jumps up to over 300k and every time I press the play button it add 1-2k onto the total memory usage. Sometimes when I run, I get a segmentation violation crash. Its’ happened quite a bit today, but I’m not able to recreate it. I looked the error up and it said that it usually happens when you access something outside of an array index.
I tried to get my program to crash and I threw everything I had at it but to no avail. I checked my memory usage and I was over 700k. I did a clear all and it only freed up about 5k. I didn’t know if it was cause by me trying to access a memory location that was leaked. Does MatLab free up its own memory, or is there a way for me to check to see if anything was leaked?
EDIT:
MATLAB crash file:T:\Temp\matlab\matlab_crash_dump.4064-1:
------------------------------------------------------------------------
Segmentation violation detected at Mon Jul 02 15:01:04 2012
------------------------------------------------------------------------
Configuration:
Crash Decoding : Disabled
Default Encoding: windows-1252
MATLAB Root : K:\PROD\wnt\matlab\2012a\win32
MATLAB Version : 7.14.0.739 (R2012a)
Operating System: Microsoft Windows XP
Processor ID : x86 Family 6 Model 23 Stepping 10, GenuineIntel
Virtual Machine : Java 1.6.0_13-b03 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode
Window System : Version 5.1 (Build 2600: Service Pack 3)
Fault Count: 1
Abnormal termination:
Segmentation violation
EDIT2:
I started in 2010a and moved to 2012a (both 32-bit) and the memory leaks only appear in 2012a. So something that was changed in-between the 2 versions is the cause of it. Simulink takes about twice as long to open in 12a as it did in 10a also.
We got a new computer, Windows 7/64-bit, and we did the same thing and there was no memory issue. The crash that I had above I think was a syntax change between versions in the s-functions that we’re using. Once I recompile those I think the crashing should go away, if what I think is wrong is actually wrong.
  2 Comments
Sean de Wolski
Sean de Wolski on 2 Jul 2012
OS and bitness?
Jenn Lee
Jenn Lee on 23 Jul 2012
I think he was asking what operating system are you using and what is its bit size

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 2 Jul 2012
Edited: Walter Roberson on 2 Jul 2012
You are using a 32 bit version of MATLAB on MS Windows, so you will run in to memory problems in some circumstances (but I would not expect crashes.)
Unfortunately I cannot find the reference posting for this at the moment. My memory is that in the 32 bit Windows version, MATLAB uses two different allocator methods depending on the size of the array being allocated, and that the MS Windows method used for the larger arrays, is not able to "give memory back" to the allocation pool under all circumstances.
  1 Comment
Walter Roberson
Walter Roberson on 2 Jul 2012
I do not know enough about MATLAB internals (especially on MS Windows) to be able to tell you from the stack trace what is happening internally in MATLAB or how to fix the problem. Stack traces should go to MATLAB technical support.

Sign in to comment.

More Answers (2)

Malcolm Lidierth
Malcolm Lidierth on 3 Jul 2012
Edited: Malcolm Lidierth on 3 Jul 2012
It looks like a mex-file is accessing MATLAB workspace memory but you are indexing using a pointer outside of the bounds of the array that has been allocated.
You see the exception sometimes but not always because its just chance whether the pointer will access a memory location that MATLAB is using and regards as valid.
Often, this turns up with an out-by-one errors running though an array. One that took me a while to figure out was pre-allocation using char(zeros...). The empty string space is reclaimed when you pass it on the RHS to a mex.

Jan
Jan on 2 Jul 2012
Without doubt this is no usual behavior of Matlab. Please try to run only built-in code, e.g. benchmark and some examples. If this looks stable, the problem is most likely in user-defined code. Usually faulty C-Mex files cause such problems.
It could be a hardware problem also. Does other software run well on your system? Did you run a RAM- and CPU-test program already?

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!