I have a code that uses a lot of memory and I'm trying to release some of 
it but without success. I made up an examples to illustrate the problem:

function memuse()
  return string(round(Int,parse(Int,readall(`ps -p 29563 -o 
rss=`))/1024),"M")
end

function test()
  for i = 1:2
   println("\ni=$i")
   a = rand(10000,10000)
   println("Created a $(memuse())")
   a = 0
   gc()
   println("Release a $(memuse())\n")

   b = rand(10000,10000)
   println("Created b $(memuse())")
   b = 0
   gc()
   println("Release b $(memuse())\n")
   
   c = rand(10000,10000)
   println("Created c $(memuse())")
   c =0
   gc()
   println("Release c $(memuse())\n")
  end
end

test()


Output:

i=1
Created a 918M
Release a 918M

Created b 1681M
Release b 1681M

Created c 2444M
Release c 2444M


i=2
Created a 3207M
Release a 2444M

Created b 3207M
Release b 2444M

Created c 3207M
Release c 2444M




This code only needs 918M to run but uses 3207M.

Questions:
Why gc() is not releasing unused memory? 
There is some way to force garbage collector to release? 
Why garbage collector releases some memory only on the second iteration?


Thanks,
Thuener

Reply via email to