MATLAB: Does MEMORY command indicate an increase in memory usage on executing a script though I do not have any variable in the workspace in MATLAB R2014b

MATLAB

Using JDBC connection to MSSQL Server database, the amount of memory being used seems to be more than two times the size of the output variables 
My output variables is of around 22 GB. However, memory command indicates that 60 GB of memory is in use after the database call. 
I think under the hood, somehow this memory leak is happening. How can I get rid of this additional memory usage. 
 
>> memory
Maximum possible array: 444201 MB (4.658e+11 bytes) *
Memory available for all arrays: 444201 MB (4.658e+11 bytes) *
Memory used by MATLAB: 4578 MB (4.800e+09 bytes)
Physical Memory (RAM): 393092 MB (4.122e+11 bytes)
>> % DOWNLOAD DATA FROM DATABASE INTO A MATLAB VARIABLE
>> memory
Maximum possible array: 389034 MB (4.079e+11 bytes) *
Memory available for all arrays: 389034 MB (4.079e+11 bytes) *
Memory used by MATLAB: 59409 MB (6.229e+10 bytes) % Memory increase to 59 GB
Physical Memory (RAM): 393092 MB (4.122e+11 bytes)
>> clear all
>>memory
Maximum possible array: 424252 MB (4.449e+11 bytes) *
Memory available for all arrays: 424252 MB (4.449e+11 bytes) *
Memory used by MATLAB: 24215 MB (2.539e+10 bytes) % Memory decrease to only 24 GB
Physical Memory (RAM): 393092 MB (4.122e+11 bytes)
As you can see, around 24 GB of extra memory is still there after executing the "clear all" command

Best Answer

The MEMORY function returns the amount of RAM memory that the operating system thinks that MATLAB is using. However, the actual memory usage in MATLAB may be different. What this means is that the additional memory, which is 35 GB int this case is probably still available for use by creating arrays in MATLAB.
In order to confirm this, after running your memory consuming code, please try to allocate random array as shown below.
>> a=rand(100000,10000);
Please check if the above command causes an increase in memory used by MATLAB using the MATLAB command. It is expected that you will not see an increase in the memory usage.
Related Question