Re: Is there memory leak in mex programming?



Does anyone ever compile m code into a c++ shared library?
It works with my application. However, it can only run for
certain time, and at the end matlab runs out of memory.

the function is coded following example in
http://www.mathworks.com/support/solutions/data/1-
2Q3TJ5.html?solution=1-2Q3TJ5

Unlike the example mentioned above, it only loop 1x. My
application is video application thus, it loops forever.
So, at the end this problem appears.


Do i have to destroy the memory / matlab memory created in
each loop?

thanks




"Jerry " <mricad@xxxxxxxxxxxxxxxxxxxxx> wrote in message
<fio3g9$olr$1@xxxxxxxxxxxxxxxxxx>...
I don't know how Matlab handle this. Here is my (probably
too naive) question:
suppose you have the following in your mexfunction:
plhs(1)=mxCreateDoubleMatrix(10,1,zeroflag);

and in Matlab, you call the compiled mex function
(mymex.mexa64) like the following:

a=zeros(10,4)
for i=1:4
a(:,i)=mymex(...)
end
Basically, you created a 10x1 vector (let's call it a
virtual variable) and assign value to it. Then this value
is
assigned to "a" in Matlab. Then what happened to the
memory
assigned to this virtual variable? will Matlab handle this
for you or the memory is lost?

Thanks!

.



Relevant Pages

  • Re: Matlab very slow with
    ... The loop that you provide illustrates a case where it is hard to ... "smart matlab" to optimize dynamic memory allocation. ...
    (comp.soft-sys.matlab)
  • Re: Matlab very slow with
    ... Do you preallocate cof before running the loop? ... I had no idea that Matlab had such issues ... allocating memory. ... Now you might ask why MATLAB can't automatically allocate the whole 100000 ...
    (comp.soft-sys.matlab)
  • Re: Incude statement - is there such a thing?
    ... but have you noticed that you get poorer compile time messages when ... > if they are constantly loaded into memory or per script. ... you had 50 statements that you wanted to execute 1000 times in a loop. ...
    (microsoft.public.scripting.vbscript)
  • Re: Read a huge text file in MATLAB
    ... If I try to read the file at once I get the> memory full error message so I am trying to read the file in segments. ... I am not getting how I can import the full file in MATLAB. ... The better route would be to try to do your processing in pieces inside the above loop if possible. ... You could certainly hold more than 1000 entries at a time unless the strings were extremely long, but still physical memory is physical memory and at some point you'll exhaust what you have. ...
    (comp.soft-sys.matlab)
  • Re: enhance m-files performance by compiling?
    ... Since I am calling it thousands of times in my project, ... I intend to use it only from within MATLAB, ... optimized the code in the loop as much as possible? ...
    (comp.soft-sys.matlab)