Re: Compile + Module =X> Memory Leak; Outer & Compile =>Memory Leak
- To: mathgroup at smc.vnet.net
- Subject: [mg40055] Re: Compile + Module =X> Memory Leak; Outer & Compile =>Memory Leak
- From: atelesforos at hotmail.com (Orestis Vantzos)
- Date: Mon, 17 Mar 2003 03:35:49 -0500 (EST)
- References: <b4mocf$inm$1@smc.vnet.net> <b4pdj8$b8r$1@smc.vnet.net> <b51adv$34t$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
I actually think that you are right! Try: $HistoryLength=0; outComp = Compile[{{XJ, _Real, 1}, {XN, _Real, 1}}, Outer[List, XJ, XN]]; MemoryInUse[] outComp[Table[Random[],{100}],Table[Random[],{100}]]; MemoryInUse[]; MemoryInUse[] There is a distinct reduction in free memory. Replacing Outer[___] with Inner[XJ,XN] eliminates the memory leak. Very weird... Orestis Bern <bgress at mail.DOTucr.DOT.edu> wrote in message news:<b51adv$34t$1 at smc.vnet.net>... > Dear Mr. Kuska, > > Thanks for this help. I was not however able to get your change of > Module to Block to work, presumably because you are asking Compile to > work with a global variable, which it won't do. > > After some experimentation I discovered that you are correct, it isn't > the fault of either Block, Module, or even With, all of which can be > used here. The real problem is Outer. Redefining the first Sum to use > Dot and Transpose, instead of Outer, fixed the problem completely. No > more memory leak. > > So my new hypothesis is that Outer + Compile causes a Memory Leak. This > is under Mathematica 4.2 & Windows2K. Does Wolfram monitor these posts? > > Regards, > > Bernard > > > The problem has nothing to do with Module[] or Block[] because > > the memory is allmost constant with the uncompiled... > > u; > > w = Compile[{{XJ, _Real, 1}, {XX, _Real, 1}, {nj, _Integer}, {ni, > > _Integer}}, > > Block[{p}, u = Table[Random[], {i, ni}, {j, nj}, {p, 0, 1}]; > > Table[Last[ > > Inverse[Sum[ > > Outer[Times, u[[i, j]], u[[i, j]]*(XX[[i]] - > > XJ[[j]])^2], {i, > > 1, ni}]].Sum[ > > Table[u[[i, j]]*XX[[i]]*(XX[[i]] - XJ[[j]])^2], {i, 1, > > ni}]], {j, nj}]], {{u, _Real, 3}}] > > > that does not change the memory *and* is significant faster than the > > original function with the local u. > > > Regards > > Jens