--track-allocation doesn't report the _net_ memory allocated, it reports the 
_gross_ memory allocation. In other words, allocate/free adds to the tally, 
even if all memory is eventually freed.

If you're still concerned about memory allocation and its likely impact on 
performance: there are some things you can do. From glancing at your code very 
briefly, a couple of comments:
- My crystal ball tells me you will soon come to adore the push! function :-)
- If you wish (and it's your choice), you can reduce allocations by doing more 
operations with scalars. For example, in computeReferenceCurrents, instead of 
computing tpu and iref arrays outside the loop, consider performing the 
equivalent operations on scalar values inside the loop.

Best,
--Tim


On Wednesday, March 11, 2015 07:41:19 AM Bartolomeo Stellato wrote:
> Hi all,
> 
> I recently started using Julia for my *Closed loop MPC simulations.* I fond
> very interesting the fact that I was able to do almost everything I was
> doing in MATLAB with Julia. Unfortunately, when I started working on more
> complex simulations I notice a *memory allocation problem*.
> 
> I am using OSX Yosemite and Julia 0.3.6. I attached a MWE that can be
> executed with include("simulation.jl")
> 
> The code executes a single simulation of the closed loop system with a *MPC
> controller* solving an optimization problem at each time step via *Gurobi
> interface*. At the end of the simulation I am interested in only *two
> performance indices* (float numbers).
> The simulation, however, takes more than 600mb of memory and, even if most
> of the declared variables local to different functions, I can't get rid of
> them afterwards with the garbage collector: gc()
> 
> I analyzed the memory allocation with julia --track-allocation=user and I
> included the generated .mem files. Probably my code is not optimized, but I
> can't understand *why all that memory doesn't get deallocated after the
> simulation*.
> 
> Is there anyone who could give me any explanation or suggestion to solve
> that problem? I need to perform several of these simulations and it is
> impossible for me to allocate for each one more than 600mb.
> 
> 
> Thank you!
> 
> Bartolomeo

Reply via email to