Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: matlab/mex function doesn't free memory
Replies: 22   Last Post: Dec 10, 2012 1:49 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Praetorian

Posts: 727
Registered: 1/25/05
Re: matlab/mex function doesn't free memory
Posted: Apr 8, 2009 8:59 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Apr 8, 12:48 am, "James Tursa" <aclassyguywithakno...@hotmail.com>
wrote:
> "gabo " <pelusacora...@hotmail.com> wrote in message <grgne9$1n...@fred.mathworks.com>...
> > "Alex Berkovich" <alex...@tx.technion> wrote in message <gi3i3u$m5...@fred.mathworks.com>...
> > > Hello all,
>
> > > I'm running a mex function that calls for c code (compiled in the same file as the mex function itself).
> > > when a simulation is done, it seems matlab doesn't release the memory it uses since i see a growing amount of memory being used by matlab (via task manager).

>
> > > it reaches the limit of my computer and then either crashes or simply continues to run forever.
>
> > > any suggestion on how to solve this problem is very appriciated.
>
> > Hi all,
>
> > It DOES seem that MatLab leaks memory when running mex files. Take a look at the following: Below is a c-mex file (trace2plane.c) that finds intersections between hyperplanes and polygonal-line traces. Run the test code (test_trace2plane.m, down at the bottom) several times and you'll discover MatLab is taking up more and more memory in the task manager. I've been trying to figure out the problem for almost a month now, any insigths or help of any kind will be much appreciated.
>
> > Gabriel
>
> -------------------------------------------------------------------------------------
>
> Here are my results:
>

> >> mex trace2plane.c
> >> feature memstats

>
>                                             1505 MB (5e1d1000)>> test_trace2plane

> >> feature memstats
>
>                                             1505 MB (5e1d1000)>> test_trace2plane

> >> feature memstats
>
>                                             1505 MB (5e1d1000)>> test_trace2plane

> >> feature memstats
>
>                                             1505 MB (5e1d1000)>> test_trace2plane

> >> feature memstats
>
>                                             1505 MB (5e1d1000)>> test_trace2plane

> >> feature memstats
>
>                                             1505 MB (5e1d1000)>> test_trace2plane

> >> feature memstats
>
>                                             1505 MB (5e1d1000)>> test_trace2plane

> >> feature memstats
>
>                                             1505 MB (5e1d1000)
>
>
>
> Other than a bunch of figures building up, I don't see any large increases in memory usage from call to call. So I can't reproduce your problem. WinXP with MSVC 8.0. How many times do you have to run it to see a problem? How much memory are you losing with each call?
>
> James Tursa


James,
I was hoping you'd see this thread. Take a look at the post from Ronan
on the 4th of February. It was directed to me but I didn't see it
until last night. Do you have any experience with calling a DLL that
uses the mxCreate* functions to allocate memory? And does the MATLAB
memory manager garbage collect that memory assuming that the DLL is
loaded and used by a mex file?

Regards,
Ashish.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.