| MATLAB Central > MATLAB Newsreader > Memory Reallocation broken in R2008b and higher |
|
|
|
Subject: Memory Reallocation broken in R2008b and higher From: James Tursa Date: 4 May, 2010 21:29:05 Message: 1 of 13 |
|
It was recently pointed out to me by a user of my mtimesx tool that if you start with a large sparse matrix A and then do the operation 0*A, the result takes just as much space as the original A even though it only needs enough space for one element. I tracked it down to the MATLAB API mxRealloc function, and indeed the behavior changes from R2008a to R2008b. In 2008a (and earlier I presume, although I only tested R2007a) when a large block is reallocated with mxRealloc the large block is freed and a new small block is allocated, thus recovering the extra memory. But for R2008b and beyond, the large block remains allocated even though only 1 element is requested in the mxRealloc call. So I checked the MATLAB intrinsic * operator and it has the same undesirable behavior so it is apparently calling the same (or similar) routine in the background. e.g., try the following: |
|
Subject: Memory Reallocation broken in R2008b and higher From: Walter Roberson Date: 4 May, 2010 22:46:56 Message: 2 of 13 |
|
James Tursa wrote: |
|
Subject: Memory Reallocation broken in R2008b and higher From: Bruno Luong Date: 5 May, 2010 07:07:03 Message: 3 of 13 |
|
"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <hrq3j1$dm$1@fred.mathworks.com>... |
|
Subject: Memory Reallocation broken in R2008b and higher From: James Tursa Date: 5 May, 2010 08:49:04 Message: 4 of 13 |
|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <hrr5en$i61$1@fred.mathworks.com>... |
|
Subject: Memory Reallocation broken in R2008b and higher From: Bruno Luong Date: 5 May, 2010 11:18:04 Message: 5 of 13 |
|
"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <hrrbe0$5kt$1@fred.mathworks.com>... |
|
Subject: Memory Reallocation broken in R2008b and higher From: Bruno Luong Date: 5 May, 2010 11:59:06 Message: 6 of 13 |
|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <hrrk5c$rkh$1@fred.mathworks.com>... |
|
Subject: Memory Reallocation broken in R2008b and higher From: Bruno Luong Date: 5 May, 2010 14:28:21 Message: 7 of 13 |
|
I have run the code and track down the pointer address as well as the memory. Here is the code |
|
Subject: Memory Reallocation broken in R2008b and higher From: Bruno Luong Date: 5 May, 2010 17:24:04 Message: 8 of 13 |
|
I makes similar test on 2010A/32 bit Vista and the mxRealloc() doesn't free the memory. My conclusion: it is buggy on 32-bit OS, but works fine on 64 bit OS. |
|
Subject: Memory Reallocation broken in R2008b and higher From: James Tursa Date: 5 May, 2010 18:00:06 Message: 9 of 13 |
|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <hrs9jk$iqe$1@fred.mathworks.com>... |
|
Subject: Memory Reallocation broken in R2008b and higher From: Roland Kruse Date: 6 May, 2010 08:54:04 Message: 10 of 13 |
|
The problem seems to be even stranger. |
|
Subject: Memory Reallocation broken in R2008b and higher From: Roland Kruse Date: 6 May, 2010 08:58:04 Message: 11 of 13 |
|
Well, of course I wanted to say that the problem is more serious on x32 than on x64. |
|
Subject: Memory Reallocation broken in R2008b and higher From: Bruno Luong Date: 6 May, 2010 09:53:03 Message: 12 of 13 |
|
"Roland Kruse" <roland.kruse@uni-oldenburg.de> wrote in message <hru03c$dh9$1@fred.mathworks.com>... |
|
Subject: Memory Reallocation broken in R2008b and higher From: Roland Kruse Date: 6 May, 2010 12:33:05 Message: 13 of 13 |
|
You may have noticed that I used "clear" to delete all variables. Even though, during each run of the program I loose ~ 70 MB till I'm out of memory. This is certainly not the correct behaviour. |
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.
| Tag Activity for This Thread | ||
|---|---|---|
| Tag | Applied By | Date/Time |
| sparse | James Tursa | 5 May, 2010 14:01:09 |
| mex | Bruno Luong | 5 May, 2010 13:24:05 |
| mxrealloc | Bruno Luong | 5 May, 2010 13:24:05 |
| bug | Bruno Luong | 5 May, 2010 13:24:05 |
